From 3138baf2c8ebe48e81d315732312796d28097add Mon Sep 17 00:00:00 2001 From: Percs <83934299+Percslol@users.noreply.github.com> Date: Thu, 10 Oct 2024 19:16:19 -0500 Subject: [PATCH 1/5] fix: double api interception --- src/client/dom/serviceworker.ts | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/client/dom/serviceworker.ts b/src/client/dom/serviceworker.ts index 9e0185b..0160305 100644 --- a/src/client/dom/serviceworker.ts +++ b/src/client/dom/serviceworker.ts @@ -14,12 +14,6 @@ export function disabled(client: ScramjetClient, self: Self) { export default function (client: ScramjetClient, self: Self) { let registration; - client.Proxy("Worklet.prototype.addModule", { - apply(ctx) { - ctx.args[0] = encodeUrl(ctx.args[0], client.meta); - }, - }); - client.Proxy("EventTarget.prototype.addEventListener", { apply(ctx) { if (registration === ctx.this) { From 4d7fa7abb60dc0c1a50508f074915795118049ea Mon Sep 17 00:00:00 2001 From: Percs <83934299+Percslol@users.noreply.github.com> Date: Thu, 10 Oct 2024 19:19:47 -0500 Subject: [PATCH 2/5] chore: prettier --- package.json | 5 ++++- src/client/client.ts | 6 +++--- src/client/dom/element.ts | 14 +++++++------- src/client/shared/error.ts | 2 +- src/shared/rewriters/url.ts | 4 ++-- static/index.html | 2 +- 6 files changed, 18 insertions(+), 15 deletions(-) diff --git a/package.json b/package.json index ac6d3fa..b744d2c 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,10 @@ "lint": "eslint ./src/ --ext .ts", "lint:fix": "eslint ./src/ --ext .ts --fix" }, - "files": ["dist", "lib"], + "files": [ + "dist", + "lib" + ], "keywords": [], "author": "", "license": "ISC", diff --git a/src/client/client.ts b/src/client/client.ts index d83cef8..12db639 100644 --- a/src/client/client.ts +++ b/src/client/client.ts @@ -108,7 +108,7 @@ export class ScramjetClient { resolve(data.port); } }); - }), + }) ); } @@ -239,7 +239,7 @@ export class ScramjetClient { h.construct = function ( constructor: any, argArray: any[], - newTarget: AnyFunction, + newTarget: AnyFunction ) { let returnValue: any = undefined; let earlyreturn = false; @@ -354,7 +354,7 @@ export class ScramjetClient { RawTrap( target: any, prop: string, - descriptor: Trap, + descriptor: Trap ): PropertyDescriptor { if (!target) return; if (!prop) return; diff --git a/src/client/dom/element.ts b/src/client/dom/element.ts index d949432..9553e07 100644 --- a/src/client/dom/element.ts +++ b/src/client/dom/element.ts @@ -52,7 +52,7 @@ export default function (client: ScramjetClient, self: typeof window) { for (const element of attrObject[attr]) { const descriptor = nativeGetOwnPropertyDescriptor( element.prototype, - attr, + attr ); Object.defineProperty(element.prototype, attr, { get() { @@ -80,7 +80,7 @@ export default function (client: ScramjetClient, self: typeof window) { base: new URL(client.url.origin), origin: new URL(client.url.origin), } as URLMeta, - true, + true ); } else if (["srcset", "imagesrcset"].includes(attr)) { value = rewriteSrcset(value, client.meta); @@ -216,8 +216,8 @@ export default function (client: ScramjetClient, self: typeof window) { return atob( client.natives["Element.prototype.getAttribute"].call( ctx.this, - "data-scramjet-script-source-src", - ), + "data-scramjet-script-source-src" + ) ); } if (ctx.this instanceof self.HTMLStyleElement) { @@ -307,7 +307,7 @@ export default function (client: ScramjetClient, self: typeof window) { ctx.args[0], client.cookieStore, client.meta, - false, + false ); } }, @@ -319,7 +319,7 @@ export default function (client: ScramjetClient, self: typeof window) { ctx.args[0], client.cookieStore, client.meta, - true, + true ); }, }); @@ -330,7 +330,7 @@ export default function (client: ScramjetClient, self: typeof window) { ctx.args[0], client.cookieStore, client.meta, - false, + false ); }, }); diff --git a/src/client/shared/error.ts b/src/client/shared/error.ts index 5051760..cf716b4 100644 --- a/src/client/shared/error.ts +++ b/src/client/shared/error.ts @@ -11,7 +11,7 @@ export default function (client: ScramjetClient, self: Self) { const url = stack[i].getFileName(); try { newstack = newstack.replaceAll(url, decodeUrl(url)); - } catch { } + } catch {} } return newstack; diff --git a/src/shared/rewriters/url.ts b/src/shared/rewriters/url.ts index bcdc6e7..f5f0fb1 100644 --- a/src/shared/rewriters/url.ts +++ b/src/shared/rewriters/url.ts @@ -45,7 +45,7 @@ export function decodeUrl(url: string | URL) { if ( tryCanParseURL(url)?.pathname.startsWith( - self.$scramjet.config.prefix + "worker", + self.$scramjet.config.prefix + "worker" ) ) { return new URL(new URL(url).searchParams.get("origin")).href; @@ -55,7 +55,7 @@ export function decodeUrl(url: string | URL) { return url; } else if (tryCanParseURL(url)) { return self.$scramjet.codec.decode( - url.slice((location.origin + self.$scramjet.config.prefix).length), + url.slice((location.origin + self.$scramjet.config.prefix).length) ); } else { return url; diff --git a/static/index.html b/static/index.html index 7c55242..e4a1835 100644 --- a/static/index.html +++ b/static/index.html @@ -4,7 +4,7 @@ Scramjet - + Date: Thu, 10 Oct 2024 19:31:35 -0500 Subject: [PATCH 3/5] chore: lint:fix --- src/client/dom/element.ts | 8 +++++--- src/client/shared/indexeddb.ts | 5 +++-- src/client/shared/requests/xmlhttprequest.ts | 11 +++++++---- src/client/shared/wrap.ts | 3 ++- src/shared/rewriters/html.ts | 8 +++++--- 5 files changed, 22 insertions(+), 13 deletions(-) diff --git a/src/client/dom/element.ts b/src/client/dom/element.ts index 9553e07..3485311 100644 --- a/src/client/dom/element.ts +++ b/src/client/dom/element.ts @@ -171,9 +171,10 @@ export default function (client: ScramjetClient, self: typeof window) { // since the prototype chain is fucked const style = ctx.get() as CSSStyleDeclaration; - return new Proxy(style, { + +return new Proxy(style, { get(t, p) { - let v = Reflect.get(t, p); + const v = Reflect.get(t, p); if (typeof v === "function") { return new Proxy(v, { apply(target, thisArg, argArray) { @@ -189,7 +190,8 @@ export default function (client: ScramjetClient, self: typeof window) { if (v == "" || typeof v !== "string") { return Reflect.set(t, p, v); } - return Reflect.set(t, p, rewriteCss(v, client.meta)); + +return Reflect.set(t, p, rewriteCss(v, client.meta)); }, }); }, diff --git a/src/client/shared/indexeddb.ts b/src/client/shared/indexeddb.ts index 1c02536..6143e1d 100644 --- a/src/client/shared/indexeddb.ts +++ b/src/client/shared/indexeddb.ts @@ -9,8 +9,9 @@ export default function (client: ScramjetClient, self: Self) { client.Trap("IDBDatabase.prototype.name", { get(ctx) { - let name = ctx.get() as string; - return name.substring(name.indexOf("@") + 1); + const name = ctx.get() as string; + +return name.substring(name.indexOf("@") + 1); }, }); } diff --git a/src/client/shared/requests/xmlhttprequest.ts b/src/client/shared/requests/xmlhttprequest.ts index cc59564..e13dac8 100644 --- a/src/client/shared/requests/xmlhttprequest.ts +++ b/src/client/shared/requests/xmlhttprequest.ts @@ -47,7 +47,7 @@ export default function (client: ScramjetClient, self: Self) { body: ctx.args[0], }); - let now = performance.now(); + const now = performance.now(); while (view.getUint8(0) === 0) { if (performance.now() - now > 1000) { throw new Error("xhr timeout"); @@ -85,13 +85,15 @@ export default function (client: ScramjetClient, self: Self) { client.RawTrap(ctx.this, "response", { get() { if (ctx.this.responseType === "arraybuffer") return bodyab.buffer; - return body; + +return body; }, }); client.RawTrap(ctx.this, "responseXML", { get() { const parser = new DOMParser(); - return parser.parseFromString(body, "text/xml"); + +return parser.parseFromString(body, "text/xml"); }, }); client.RawTrap(ctx.this, "getAllResponseHeaders", { @@ -104,7 +106,8 @@ export default function (client: ScramjetClient, self: Self) { return (header: string) => { const re = new RegExp(`^${header}: (.*)$`, "m"); const match = re.exec(headers); - return match ? match[1] : null; + +return match ? match[1] : null; }; }, }); diff --git a/src/client/shared/wrap.ts b/src/client/shared/wrap.ts index c28a5b6..fe9b56f 100644 --- a/src/client/shared/wrap.ts +++ b/src/client/shared/wrap.ts @@ -66,7 +66,8 @@ export default function (client: ScramjetClient, self: typeof globalThis) { if (typeof v === "string" && v.includes("scramjet")) { debugger; } - return v; + +return v; }; // location = "..." can't be rewritten as wrapfn(location) = ..., so instead it will actually be rewritten as diff --git a/src/shared/rewriters/html.ts b/src/shared/rewriters/html.ts index a053d10..f36ec64 100644 --- a/src/shared/rewriters/html.ts +++ b/src/shared/rewriters/html.ts @@ -219,7 +219,7 @@ function traverseParsedHtml( ) { let js = node.children[0].data; // node.attribs[`data-scramjet-script-source-src`] = btoa(js); - node.attribs[`data-scramjet-script-source-src`] = bytesToBase64( + node.attribs["data-scramjet-script-source-src"] = bytesToBase64( new TextEncoder().encode(js) ); const htmlcomment = //g; @@ -272,12 +272,14 @@ export function rewriteSrcset(srcset: string, meta: URLMeta) { function base64ToBytes(base64) { const binString = atob(base64); - return Uint8Array.from(binString, (m) => m.codePointAt(0)); + +return Uint8Array.from(binString, (m) => m.codePointAt(0)); } function bytesToBase64(bytes: Uint8Array) { const binString = Array.from(bytes, (byte) => String.fromCodePoint(byte) ).join(""); - return btoa(binString); + +return btoa(binString); } From 3436d858882a51628345c0844c234e67dc79fd62 Mon Sep 17 00:00:00 2001 From: wearrrrr Date: Thu, 10 Oct 2024 19:33:18 -0500 Subject: [PATCH 4/5] disable @typescript-eslint/ban-types --- .eslintrc.json | 1 + 1 file changed, 1 insertion(+) diff --git a/.eslintrc.json b/.eslintrc.json index 3915170..2bd8865 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -18,6 +18,7 @@ "no-undef": "off", "@typescript-eslint/no-explicit-any": "off", "@typescript-eslint/ban-ts-comment": "off", + "@typescript-eslint/ban-types": "off", "@typescript-eslint/no-unused-vars": [ "warn", { From 0d4ee9ee96f59591caff8d48ab508d7b2aa86f62 Mon Sep 17 00:00:00 2001 From: wearrrrr Date: Thu, 10 Oct 2024 19:35:08 -0500 Subject: [PATCH 5/5] chore: prettier.... TWO! --- src/client/dom/element.ts | 8 ++++---- src/client/shared/indexeddb.ts | 4 ++-- src/client/shared/requests/xmlhttprequest.ts | 12 ++++++------ src/client/shared/wrap.ts | 4 ++-- src/shared/rewriters/html.ts | 8 ++++---- 5 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/client/dom/element.ts b/src/client/dom/element.ts index 3485311..6aec14c 100644 --- a/src/client/dom/element.ts +++ b/src/client/dom/element.ts @@ -171,8 +171,8 @@ export default function (client: ScramjetClient, self: typeof window) { // since the prototype chain is fucked const style = ctx.get() as CSSStyleDeclaration; - -return new Proxy(style, { + + return new Proxy(style, { get(t, p) { const v = Reflect.get(t, p); if (typeof v === "function") { @@ -190,8 +190,8 @@ return new Proxy(style, { if (v == "" || typeof v !== "string") { return Reflect.set(t, p, v); } - -return Reflect.set(t, p, rewriteCss(v, client.meta)); + + return Reflect.set(t, p, rewriteCss(v, client.meta)); }, }); }, diff --git a/src/client/shared/indexeddb.ts b/src/client/shared/indexeddb.ts index 6143e1d..4b57257 100644 --- a/src/client/shared/indexeddb.ts +++ b/src/client/shared/indexeddb.ts @@ -10,8 +10,8 @@ export default function (client: ScramjetClient, self: Self) { client.Trap("IDBDatabase.prototype.name", { get(ctx) { const name = ctx.get() as string; - -return name.substring(name.indexOf("@") + 1); + + return name.substring(name.indexOf("@") + 1); }, }); } diff --git a/src/client/shared/requests/xmlhttprequest.ts b/src/client/shared/requests/xmlhttprequest.ts index e13dac8..05ea88e 100644 --- a/src/client/shared/requests/xmlhttprequest.ts +++ b/src/client/shared/requests/xmlhttprequest.ts @@ -85,15 +85,15 @@ export default function (client: ScramjetClient, self: Self) { client.RawTrap(ctx.this, "response", { get() { if (ctx.this.responseType === "arraybuffer") return bodyab.buffer; - -return body; + + return body; }, }); client.RawTrap(ctx.this, "responseXML", { get() { const parser = new DOMParser(); - -return parser.parseFromString(body, "text/xml"); + + return parser.parseFromString(body, "text/xml"); }, }); client.RawTrap(ctx.this, "getAllResponseHeaders", { @@ -106,8 +106,8 @@ return parser.parseFromString(body, "text/xml"); return (header: string) => { const re = new RegExp(`^${header}: (.*)$`, "m"); const match = re.exec(headers); - -return match ? match[1] : null; + + return match ? match[1] : null; }; }, }); diff --git a/src/client/shared/wrap.ts b/src/client/shared/wrap.ts index fe9b56f..f364a12 100644 --- a/src/client/shared/wrap.ts +++ b/src/client/shared/wrap.ts @@ -66,8 +66,8 @@ export default function (client: ScramjetClient, self: typeof globalThis) { if (typeof v === "string" && v.includes("scramjet")) { debugger; } - -return v; + + return v; }; // location = "..." can't be rewritten as wrapfn(location) = ..., so instead it will actually be rewritten as diff --git a/src/shared/rewriters/html.ts b/src/shared/rewriters/html.ts index f36ec64..b176411 100644 --- a/src/shared/rewriters/html.ts +++ b/src/shared/rewriters/html.ts @@ -272,14 +272,14 @@ export function rewriteSrcset(srcset: string, meta: URLMeta) { function base64ToBytes(base64) { const binString = atob(base64); - -return Uint8Array.from(binString, (m) => m.codePointAt(0)); + + return Uint8Array.from(binString, (m) => m.codePointAt(0)); } function bytesToBase64(bytes: Uint8Array) { const binString = Array.from(bytes, (byte) => String.fromCodePoint(byte) ).join(""); - -return btoa(binString); + + return btoa(binString); }