chore: update dependencies and code cleanup

This commit is contained in:
Percs 2024-11-23 15:16:53 -06:00
parent a8f9073986
commit c92430ede2
6 changed files with 349 additions and 347 deletions

View file

@ -29,31 +29,31 @@
"author": "",
"license": "ISC",
"devDependencies": {
"@eslint/eslintrc": "^3.1.0",
"@eslint/js": "^9.14.0",
"@eslint/eslintrc": "^3.2.0",
"@eslint/js": "^9.15.0",
"@estruyf/github-actions-reporter": "^1.9.2",
"@fastify/static": "^8.0.2",
"@fastify/static": "^8.0.3",
"@mercuryworkshop/bare-as-module3": "^2.2.5",
"@mercuryworkshop/epoxy-transport": "^2.1.26",
"@mercuryworkshop/libcurl-transport": "^1.3.14",
"@nebula-services/bare-server-node": "^2.0.4",
"@playwright/test": "^1.48.2",
"@playwright/test": "^1.49.0",
"@rsdoctor/rspack-plugin": "^0.4.8",
"@rspack/cli": "^1.1.0",
"@rspack/core": "^1.1.0",
"@rspack/cli": "^1.1.3",
"@rspack/core": "^1.1.3",
"@types/eslint": "^9.6.1",
"@types/estree": "^1.0.6",
"@types/node": "^22.9.0",
"@types/serviceworker": "^0.0.103",
"@typescript-eslint/eslint-plugin": "^8.13.0",
"@typescript-eslint/parser": "^8.13.0",
"@types/node": "^22.9.3",
"@types/serviceworker": "^0.0.105",
"@typescript-eslint/eslint-plugin": "^8.15.0",
"@typescript-eslint/parser": "^8.15.0",
"dotenv": "^16.4.5",
"eslint": "^9.14.0",
"eslint": "^9.15.0",
"fastify": "^5.1.0",
"playwright": "^1.48.2",
"playwright": "^1.49.0",
"prettier": "^3.3.3",
"tslib": "^2.8.1",
"typescript": "^5.6.3",
"typescript": "^5.7.2",
"wisp-server-node": "^1.1.7"
},
"dependencies": {

583
pnpm-lock.yaml generated

File diff suppressed because it is too large Load diff

View file

@ -233,13 +233,11 @@ export default function (client: ScramjetClient, self: typeof window) {
const realwin = ctx.get() as Window;
if (!realwin) return realwin;
if (SCRAMJETCLIENT in realwin.self) {
// if (realwin.location.href.includes("accounts.google.com")) return null; // don't question it
return realwin.self[SCRAMJETCLIENT].globalProxy;
if (SCRAMJETCLIENT in realwin) {
return realwin[SCRAMJETCLIENT].globalProxy;
} else {
// hook the iframe
const newclient = new ScramjetClient(realwin.self);
const newclient = new ScramjetClient(realwin);
newclient.hook();
return newclient.globalProxy;
@ -254,10 +252,10 @@ export default function (client: ScramjetClient, self: typeof window) {
const realwin = contentwindow.apply(ctx.this);
if (!realwin) return realwin;
if (SCRAMJETCLIENT in realwin.self) {
return realwin.self[SCRAMJETCLIENT].documentProxy;
if (SCRAMJETCLIENT in realwin) {
return realwin[SCRAMJETCLIENT].documentProxy;
} else {
const newclient = new ScramjetClient(realwin.self);
const newclient = new ScramjetClient(realwin);
newclient.hook();
return newclient.documentProxy;

View file

@ -14,10 +14,10 @@ export default function (client: ScramjetClient) {
if (!realwin) return ctx.return(realwin);
if (SCRAMJETCLIENT in realwin.self) {
return ctx.return(realwin.self[SCRAMJETCLIENT].globalProxy.window);
if (SCRAMJETCLIENT in realwin) {
return ctx.return(realwin[SCRAMJETCLIENT].globalProxy);
} else {
const newclient = new ScramjetClient(realwin.self);
const newclient = new ScramjetClient(realwin);
// hook the opened window
newclient.hook();
@ -31,8 +31,8 @@ export default function (client: ScramjetClient) {
get(ctx) {
const realwin = ctx.get() as Window;
if (realwin && SCRAMJETCLIENT in realwin.self) {
return realwin.self[SCRAMJETCLIENT].globalProxy;
if (realwin && SCRAMJETCLIENT in realwin) {
return realwin[SCRAMJETCLIENT].globalProxy;
} else {
// the opener has to have been already hooked, so if we reach here then it's a real window
return undefined;

View file

@ -13,9 +13,9 @@ export function createWrapFn(client: ScramjetClient, self: typeof globalThis) {
if (iswindow) {
if (identifier === self.parent) {
if (SCRAMJETCLIENT in self.parent.self) {
if (SCRAMJETCLIENT in self.parent) {
// ... then we're in a subframe, and the parent frame is also in a proxy context, so we should return its proxy
return self.parent.self[SCRAMJETCLIENT].globalProxy;
return self.parent[SCRAMJETCLIENT].globalProxy;
} else {
// ... then we should pretend we aren't nested and return the current window
return client.globalProxy;
@ -24,7 +24,7 @@ export function createWrapFn(client: ScramjetClient, self: typeof globalThis) {
return client.documentProxy;
} else if (identifier === self.top) {
// instead of returning top, we need to return the uppermost parent that's inside a scramjet context
let current = self.self;
let current = self;
for (;;) {
const test = current.parent.self;
@ -37,7 +37,7 @@ export function createWrapFn(client: ScramjetClient, self: typeof globalThis) {
current = test;
}
return current[SCRAMJETCLIENT].globalProxy.window;
return current[SCRAMJETCLIENT].globalProxy;
}
}

View file

@ -35,33 +35,36 @@ self.addEventListener("message", ({ data }) => {
});
scramjet.addEventListener("request", (e) => {
let headers = {};
if (playgroundData && e.url.href === playgroundData.origin + "/") {
headers["content-type"] = "text/html";
e.response = new Response(playgroundData.html, {
headers,
});
} else if (
playgroundData &&
e.url.href === playgroundData.origin + "/style.css"
) {
headers["content-type"] = "text/css";
e.response = new Response(playgroundData.css, {
headers,
});
} else if (
playgroundData &&
e.url.href === playgroundData.origin + "/script.js"
) {
headers["content-type"] = "application/javascript";
e.response = new Response(playgroundData.js, {
headers,
});
if (playgroundData && e.url.href.startsWith(playgroundData.origin)) {
const headers = {};
const origin = playgroundData.origin;
if (e.url.href === origin + "/") {
headers["content-type"] = "text/html";
e.response = new Response(playgroundData.html, {
headers,
});
} else if (e.url.href === origin + "/style.css") {
headers["content-type"] = "text/css";
e.response = new Response(playgroundData.css, {
headers,
});
} else if (e.url.href === origin + "/script.js") {
headers["content-type"] = "application/javascript";
e.response = new Response(playgroundData.js, {
headers,
});
e.response.rawHeaders = headers;
e.response.rawResponse = {
body: e.response.body,
headers: headers,
status: e.response.status,
statusText: e.response.statusText,
};
e.response.finalURL = e.url.toString();
} else {
return;
}
} else {
return;
}
if (playgroundData) {
e.response.rawHeaders = headers;
e.response.finalURL = e.url.toString();
}
});