kill snapshot.ts (untested)

This commit is contained in:
velzie 2024-08-25 14:55:20 -04:00
parent 9a39435c7d
commit 7f398cda17
No known key found for this signature in database
GPG key ID: 048413F95F0DDE1F
7 changed files with 33 additions and 18 deletions

View file

@ -4,7 +4,7 @@ import { rewriteJs } from "../shared";
function rewriteFunction(ctx: ProxyCtx) {
const stringifiedFunction = ctx.fn(...ctx.args).toString();
ctx.return(Function(`return ${rewriteJs(stringifiedFunction)}`)());
ctx.return(ctx.fn(`return ${rewriteJs(stringifiedFunction)}`)());
}
export default function (client: ScramjetClient, self: Self) {

View file

@ -1,6 +1,9 @@
import { ScramjetClient } from "../client";
import { config, encodeUrl } from "../shared";
export default function (client, self) {
export default function (client: ScramjetClient, self: Self) {
const Function = client.natives.Function;
self[config.importfn] = function (base: string) {
return function (url: string) {
const resolved = new URL(url, base).href;

View file

@ -8,7 +8,8 @@ export default function (client: ScramjetClient, self: typeof globalThis) {
if (args[0].startsWith("blob:") || args[0].startsWith("data:")) {
if (args[0].startsWith("blob:")) {
args[0] =
"data:application/javascript;base64," + btoa(syncfetch(args[0]));
"data:application/javascript;base64," +
btoa(syncfetch(client, args[0]));
}
args[0] = "/scramjet/worker?data=" + args[0];
@ -30,9 +31,12 @@ export default function (client: ScramjetClient, self: typeof globalThis) {
});
}
function syncfetch(url: string) {
function syncfetch(client: ScramjetClient, url: string) {
const xhr = new XMLHttpRequest();
xhr.open("GET", url, false);
const realOpen = client.natives["XMLHttpRequest.prototype.open"].bind(xhr);
realOpen("GET", url, false);
xhr.send();
return xhr.responseText;