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": "", "author": "",
"license": "ISC", "license": "ISC",
"devDependencies": { "devDependencies": {
"@eslint/eslintrc": "^3.1.0", "@eslint/eslintrc": "^3.2.0",
"@eslint/js": "^9.14.0", "@eslint/js": "^9.15.0",
"@estruyf/github-actions-reporter": "^1.9.2", "@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/bare-as-module3": "^2.2.5",
"@mercuryworkshop/epoxy-transport": "^2.1.26", "@mercuryworkshop/epoxy-transport": "^2.1.26",
"@mercuryworkshop/libcurl-transport": "^1.3.14", "@mercuryworkshop/libcurl-transport": "^1.3.14",
"@nebula-services/bare-server-node": "^2.0.4", "@nebula-services/bare-server-node": "^2.0.4",
"@playwright/test": "^1.48.2", "@playwright/test": "^1.49.0",
"@rsdoctor/rspack-plugin": "^0.4.8", "@rsdoctor/rspack-plugin": "^0.4.8",
"@rspack/cli": "^1.1.0", "@rspack/cli": "^1.1.3",
"@rspack/core": "^1.1.0", "@rspack/core": "^1.1.3",
"@types/eslint": "^9.6.1", "@types/eslint": "^9.6.1",
"@types/estree": "^1.0.6", "@types/estree": "^1.0.6",
"@types/node": "^22.9.0", "@types/node": "^22.9.3",
"@types/serviceworker": "^0.0.103", "@types/serviceworker": "^0.0.105",
"@typescript-eslint/eslint-plugin": "^8.13.0", "@typescript-eslint/eslint-plugin": "^8.15.0",
"@typescript-eslint/parser": "^8.13.0", "@typescript-eslint/parser": "^8.15.0",
"dotenv": "^16.4.5", "dotenv": "^16.4.5",
"eslint": "^9.14.0", "eslint": "^9.15.0",
"fastify": "^5.1.0", "fastify": "^5.1.0",
"playwright": "^1.48.2", "playwright": "^1.49.0",
"prettier": "^3.3.3", "prettier": "^3.3.3",
"tslib": "^2.8.1", "tslib": "^2.8.1",
"typescript": "^5.6.3", "typescript": "^5.7.2",
"wisp-server-node": "^1.1.7" "wisp-server-node": "^1.1.7"
}, },
"dependencies": { "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; const realwin = ctx.get() as Window;
if (!realwin) return realwin; if (!realwin) return realwin;
if (SCRAMJETCLIENT in realwin.self) { if (SCRAMJETCLIENT in realwin) {
// if (realwin.location.href.includes("accounts.google.com")) return null; // don't question it return realwin[SCRAMJETCLIENT].globalProxy;
return realwin.self[SCRAMJETCLIENT].globalProxy;
} else { } else {
// hook the iframe // hook the iframe
const newclient = new ScramjetClient(realwin.self); const newclient = new ScramjetClient(realwin);
newclient.hook(); newclient.hook();
return newclient.globalProxy; return newclient.globalProxy;
@ -254,10 +252,10 @@ export default function (client: ScramjetClient, self: typeof window) {
const realwin = contentwindow.apply(ctx.this); const realwin = contentwindow.apply(ctx.this);
if (!realwin) return realwin; if (!realwin) return realwin;
if (SCRAMJETCLIENT in realwin.self) { if (SCRAMJETCLIENT in realwin) {
return realwin.self[SCRAMJETCLIENT].documentProxy; return realwin[SCRAMJETCLIENT].documentProxy;
} else { } else {
const newclient = new ScramjetClient(realwin.self); const newclient = new ScramjetClient(realwin);
newclient.hook(); newclient.hook();
return newclient.documentProxy; return newclient.documentProxy;

View file

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

View file

@ -13,9 +13,9 @@ export function createWrapFn(client: ScramjetClient, self: typeof globalThis) {
if (iswindow) { if (iswindow) {
if (identifier === self.parent) { 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 // ... 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 { } else {
// ... then we should pretend we aren't nested and return the current window // ... then we should pretend we aren't nested and return the current window
return client.globalProxy; return client.globalProxy;
@ -24,7 +24,7 @@ export function createWrapFn(client: ScramjetClient, self: typeof globalThis) {
return client.documentProxy; return client.documentProxy;
} else if (identifier === self.top) { } else if (identifier === self.top) {
// instead of returning top, we need to return the uppermost parent that's inside a scramjet context // 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 (;;) { for (;;) {
const test = current.parent.self; const test = current.parent.self;
@ -37,7 +37,7 @@ export function createWrapFn(client: ScramjetClient, self: typeof globalThis) {
current = test; 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) => { scramjet.addEventListener("request", (e) => {
let headers = {}; if (playgroundData && e.url.href.startsWith(playgroundData.origin)) {
if (playgroundData && e.url.href === playgroundData.origin + "/") { const headers = {};
const origin = playgroundData.origin;
if (e.url.href === origin + "/") {
headers["content-type"] = "text/html"; headers["content-type"] = "text/html";
e.response = new Response(playgroundData.html, { e.response = new Response(playgroundData.html, {
headers, headers,
}); });
} else if ( } else if (e.url.href === origin + "/style.css") {
playgroundData &&
e.url.href === playgroundData.origin + "/style.css"
) {
headers["content-type"] = "text/css"; headers["content-type"] = "text/css";
e.response = new Response(playgroundData.css, { e.response = new Response(playgroundData.css, {
headers, headers,
}); });
} else if ( } else if (e.url.href === origin + "/script.js") {
playgroundData &&
e.url.href === playgroundData.origin + "/script.js"
) {
headers["content-type"] = "application/javascript"; headers["content-type"] = "application/javascript";
e.response = new Response(playgroundData.js, { e.response = new Response(playgroundData.js, {
headers, 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 { } else {
return; return;
} }
if (playgroundData) { } else {
e.response.rawHeaders = headers; return;
e.response.finalURL = e.url.toString();
} }
}); });