From c1f7ebf752ddb6d90bbed76a0fc803d10f8c7ef0 Mon Sep 17 00:00:00 2001 From: Percs <83934299+Percslol@users.noreply.github.com> Date: Mon, 12 May 2025 13:50:46 -0500 Subject: [PATCH] fix: more text stuff, make sure websocketstream returns a arraybuffer always --- package.json | 4 +- pnpm-lock.yaml | 130 +++++++++++++----------- src/client/dom/element.ts | 18 ++-- src/client/shared/requests/websocket.ts | 9 +- 4 files changed, 88 insertions(+), 73 deletions(-) diff --git a/package.json b/package.json index a42a869..4c35d27 100644 --- a/package.json +++ b/package.json @@ -48,8 +48,8 @@ "@types/estree": "^1.0.7", "@types/node": "^22.15.17", "@types/serviceworker": "^0.0.134", - "@typescript-eslint/eslint-plugin": "^8.32.0", - "@typescript-eslint/parser": "^8.32.0", + "@typescript-eslint/eslint-plugin": "^8.32.1", + "@typescript-eslint/parser": "^8.32.1", "dotenv": "^16.5.0", "eslint": "^9.26.0", "fastify": "^5.3.2", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index c85d34c..14b64b9 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -82,11 +82,11 @@ importers: specifier: ^0.0.134 version: 0.0.134 '@typescript-eslint/eslint-plugin': - specifier: ^8.32.0 - version: 8.32.0(@typescript-eslint/parser@8.32.0(eslint@9.26.0)(typescript@5.8.3))(eslint@9.26.0)(typescript@5.8.3) + specifier: ^8.32.1 + version: 8.32.1(@typescript-eslint/parser@8.32.1(eslint@9.26.0)(typescript@5.8.3))(eslint@9.26.0)(typescript@5.8.3) '@typescript-eslint/parser': - specifier: ^8.32.0 - version: 8.32.0(eslint@9.26.0)(typescript@5.8.3) + specifier: ^8.32.1 + version: 8.32.1(eslint@9.26.0)(typescript@5.8.3) dotenv: specifier: ^16.5.0 version: 16.5.0 @@ -298,8 +298,8 @@ packages: resolution: {integrity: sha512-egc9jbBmNqPXGOkvOOG142SLaBL3jBkz0IGnhYYWOnmg5FeC6KfGSRU5xlk+dKYecE3tuH03bFNi3/vBAOoJKA==} hasBin: true - '@modelcontextprotocol/sdk@1.11.1': - resolution: {integrity: sha512-9LfmxKTb1v+vUS1/emSk1f5ePmTLkb9Le9AxOB5T0XM59EUumwcS45z05h7aiZx3GI0Bl7mjb3FMEglYj+acuQ==} + '@modelcontextprotocol/sdk@1.11.2': + resolution: {integrity: sha512-H9vwztj5OAqHg9GockCQC06k1natgcxWQSRpQcPJf6i5+MWBzfKkRtxGbjQf0X2ihii0ffLZCRGbYV2f2bjNCQ==} engines: {node: '>=18'} '@module-federation/error-codes@0.13.1': @@ -550,51 +550,51 @@ packages: '@types/ws@8.18.1': resolution: {integrity: sha512-ThVF6DCVhA8kUGy+aazFQ4kXQ7E1Ty7A3ypFOe0IcJV8O/M511G99AW24irKrW56Wt44yG9+ij8FaqoBGkuBXg==} - '@typescript-eslint/eslint-plugin@8.32.0': - resolution: {integrity: sha512-/jU9ettcntkBFmWUzzGgsClEi2ZFiikMX5eEQsmxIAWMOn4H3D4rvHssstmAHGVvrYnaMqdWWWg0b5M6IN/MTQ==} + '@typescript-eslint/eslint-plugin@8.32.1': + resolution: {integrity: sha512-6u6Plg9nP/J1GRpe/vcjjabo6Uc5YQPAMxsgQyGC/I0RuukiG1wIe3+Vtg3IrSCVJDmqK3j8adrtzXSENRtFgg==} engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0} peerDependencies: '@typescript-eslint/parser': ^8.0.0 || ^8.0.0-alpha.0 eslint: ^8.57.0 || ^9.0.0 typescript: '>=4.8.4 <5.9.0' - '@typescript-eslint/parser@8.32.0': - resolution: {integrity: sha512-B2MdzyWxCE2+SqiZHAjPphft+/2x2FlO9YBx7eKE1BCb+rqBlQdhtAEhzIEdozHd55DXPmxBdpMygFJjfjjA9A==} + '@typescript-eslint/parser@8.32.1': + resolution: {integrity: sha512-LKMrmwCPoLhM45Z00O1ulb6jwyVr2kr3XJp+G+tSEZcbauNnScewcQwtJqXDhXeYPDEjZ8C1SjXm015CirEmGg==} engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0} peerDependencies: eslint: ^8.57.0 || ^9.0.0 typescript: '>=4.8.4 <5.9.0' - '@typescript-eslint/scope-manager@8.32.0': - resolution: {integrity: sha512-jc/4IxGNedXkmG4mx4nJTILb6TMjL66D41vyeaPWvDUmeYQzF3lKtN15WsAeTr65ce4mPxwopPSo1yUUAWw0hQ==} + '@typescript-eslint/scope-manager@8.32.1': + resolution: {integrity: sha512-7IsIaIDeZn7kffk7qXC3o6Z4UblZJKV3UBpkvRNpr5NSyLji7tvTcvmnMNYuYLyh26mN8W723xpo3i4MlD33vA==} engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0} - '@typescript-eslint/type-utils@8.32.0': - resolution: {integrity: sha512-t2vouuYQKEKSLtJaa5bB4jHeha2HJczQ6E5IXPDPgIty9EqcJxpr1QHQ86YyIPwDwxvUmLfP2YADQ5ZY4qddZg==} + '@typescript-eslint/type-utils@8.32.1': + resolution: {integrity: sha512-mv9YpQGA8iIsl5KyUPi+FGLm7+bA4fgXaeRcFKRDRwDMu4iwrSHeDPipwueNXhdIIZltwCJv+NkxftECbIZWfA==} engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0} peerDependencies: eslint: ^8.57.0 || ^9.0.0 typescript: '>=4.8.4 <5.9.0' - '@typescript-eslint/types@8.32.0': - resolution: {integrity: sha512-O5Id6tGadAZEMThM6L9HmVf5hQUXNSxLVKeGJYWNhhVseps/0LddMkp7//VDkzwJ69lPL0UmZdcZwggj9akJaA==} + '@typescript-eslint/types@8.32.1': + resolution: {integrity: sha512-YmybwXUJcgGqgAp6bEsgpPXEg6dcCyPyCSr0CAAueacR/CCBi25G3V8gGQ2kRzQRBNol7VQknxMs9HvVa9Rvfg==} engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0} - '@typescript-eslint/typescript-estree@8.32.0': - resolution: {integrity: sha512-pU9VD7anSCOIoBFnhTGfOzlVFQIA1XXiQpH/CezqOBaDppRwTglJzCC6fUQGpfwey4T183NKhF1/mfatYmjRqQ==} + '@typescript-eslint/typescript-estree@8.32.1': + resolution: {integrity: sha512-Y3AP9EIfYwBb4kWGb+simvPaqQoT5oJuzzj9m0i6FCY6SPvlomY2Ei4UEMm7+FXtlNJbor80ximyslzaQF6xhg==} engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0} peerDependencies: typescript: '>=4.8.4 <5.9.0' - '@typescript-eslint/utils@8.32.0': - resolution: {integrity: sha512-8S9hXau6nQ/sYVtC3D6ISIDoJzS1NsCK+gluVhLN2YkBPX+/1wkwyUiDKnxRh15579WoOIyVWnoyIf3yGI9REw==} + '@typescript-eslint/utils@8.32.1': + resolution: {integrity: sha512-DsSFNIgLSrc89gpq1LJB7Hm1YpuhK086DRDJSNrewcGvYloWW1vZLHBTIvarKZDcAORIy/uWNx8Gad+4oMpkSA==} engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0} peerDependencies: eslint: ^8.57.0 || ^9.0.0 typescript: '>=4.8.4 <5.9.0' - '@typescript-eslint/visitor-keys@8.32.0': - resolution: {integrity: sha512-1rYQTCLFFzOI5Nl0c8LUpJT8HxpwVRn9E4CkMsYfuN6ctmQqExjSTzzSk0Tz2apmXy7WU6/6fyaZVVA/thPN+w==} + '@typescript-eslint/visitor-keys@8.32.1': + resolution: {integrity: sha512-ar0tjQfObzhSaW3C3QNmTc5ofj0hDoNQ5XWrCy6zDyabdr0TWhCkClp+rywGNj/odAFBVzzJrK4tEq5M4Hmu4w==} engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0} '@webassemblyjs/ast@1.14.1': @@ -1065,8 +1065,8 @@ packages: ee-first@1.1.1: resolution: {integrity: sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow==} - electron-to-chromium@1.5.151: - resolution: {integrity: sha512-Rl6uugut2l9sLojjS4H4SAr3A4IgACMLgpuEMPYCVcKydzfyPrn5absNRju38IhQOf/NwjJY8OGWjlteqYeBCA==} + electron-to-chromium@1.5.152: + resolution: {integrity: sha512-xBOfg/EBaIlVsHipHl2VdTPJRSvErNUaqW8ejTq5OlOlIYx1wOllCHsAvAIrr55jD1IYEfdR86miUEt8H5IeJg==} emoji-regex@8.0.0: resolution: {integrity: sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==} @@ -1483,6 +1483,10 @@ packages: resolution: {integrity: sha512-hsBTNUqQTDwkWtcdYI2i06Y/nUBEsNEDJKjWdigLvegy8kDuJAS8uRlpkkcQpyEXL0Z/pjDy5HBmMjRCJ2gq+g==} engines: {node: '>= 4'} + ignore@7.0.4: + resolution: {integrity: sha512-gJzzk+PQNznz8ysRrC0aOkBNVRBDtE1n53IqyqEf3PXrYwomFs5q4pGMizBMJF+ykh03insJ27hB8gSrD2Hn8A==} + engines: {node: '>= 4'} + import-fresh@3.3.1: resolution: {integrity: sha512-TR3KfrTZTYLPB6jUjfx6MF9WcWrHL9su5TObK4ZkYgBdWKPOFoSoQIdEuTuR82pmtxH2spWG9h6etwfr1pLBqQ==} engines: {node: '>=6'} @@ -2093,8 +2097,8 @@ packages: resolution: {integrity: sha512-th5B4L2U+eGLq1TVh7zNRGBapioSORUeymIydxgFpwww9d2qyKvtuPU2jJuHvYAwwqi2Y596QBL3eEqcPEYL8Q==} engines: {node: '>=10'} - semver@7.7.1: - resolution: {integrity: sha512-hlq8tAfn0m/61p4BVRcPzIGr6LKiMwo4VM6dGi6pt4qcRkmNzTcWq6eCEjEh+qXjkMDvPlOFFSGwQjoEa6gyMA==} + semver@7.7.2: + resolution: {integrity: sha512-RF0Fw+rO5AMf9MAyaRXI4AV0Ulj5lMHqVxxdSgiVbixSCXoEmmX/jk0CuJw4+3SqroYO9VoUh+HcuJivvtJemA==} engines: {node: '>=10'} hasBin: true @@ -2745,7 +2749,7 @@ snapshots: transitivePeerDependencies: - utf-8-validate - '@modelcontextprotocol/sdk@1.11.1': + '@modelcontextprotocol/sdk@1.11.2': dependencies: content-type: 1.0.5 cors: 2.8.5 @@ -2840,7 +2844,7 @@ snapshots: fs-extra: 11.3.0 lodash: 4.17.21 path-browserify: 1.0.1 - semver: 7.7.1 + semver: 7.7.2 source-map: 0.7.4 webpack-bundle-analyzer: 4.10.2(bufferutil@4.0.9) transitivePeerDependencies: @@ -3152,44 +3156,44 @@ snapshots: dependencies: '@types/node': 22.15.17 - '@typescript-eslint/eslint-plugin@8.32.0(@typescript-eslint/parser@8.32.0(eslint@9.26.0)(typescript@5.8.3))(eslint@9.26.0)(typescript@5.8.3)': + '@typescript-eslint/eslint-plugin@8.32.1(@typescript-eslint/parser@8.32.1(eslint@9.26.0)(typescript@5.8.3))(eslint@9.26.0)(typescript@5.8.3)': dependencies: '@eslint-community/regexpp': 4.12.1 - '@typescript-eslint/parser': 8.32.0(eslint@9.26.0)(typescript@5.8.3) - '@typescript-eslint/scope-manager': 8.32.0 - '@typescript-eslint/type-utils': 8.32.0(eslint@9.26.0)(typescript@5.8.3) - '@typescript-eslint/utils': 8.32.0(eslint@9.26.0)(typescript@5.8.3) - '@typescript-eslint/visitor-keys': 8.32.0 + '@typescript-eslint/parser': 8.32.1(eslint@9.26.0)(typescript@5.8.3) + '@typescript-eslint/scope-manager': 8.32.1 + '@typescript-eslint/type-utils': 8.32.1(eslint@9.26.0)(typescript@5.8.3) + '@typescript-eslint/utils': 8.32.1(eslint@9.26.0)(typescript@5.8.3) + '@typescript-eslint/visitor-keys': 8.32.1 eslint: 9.26.0 graphemer: 1.4.0 - ignore: 5.3.2 + ignore: 7.0.4 natural-compare: 1.4.0 ts-api-utils: 2.1.0(typescript@5.8.3) typescript: 5.8.3 transitivePeerDependencies: - supports-color - '@typescript-eslint/parser@8.32.0(eslint@9.26.0)(typescript@5.8.3)': + '@typescript-eslint/parser@8.32.1(eslint@9.26.0)(typescript@5.8.3)': dependencies: - '@typescript-eslint/scope-manager': 8.32.0 - '@typescript-eslint/types': 8.32.0 - '@typescript-eslint/typescript-estree': 8.32.0(typescript@5.8.3) - '@typescript-eslint/visitor-keys': 8.32.0 + '@typescript-eslint/scope-manager': 8.32.1 + '@typescript-eslint/types': 8.32.1 + '@typescript-eslint/typescript-estree': 8.32.1(typescript@5.8.3) + '@typescript-eslint/visitor-keys': 8.32.1 debug: 4.4.0 eslint: 9.26.0 typescript: 5.8.3 transitivePeerDependencies: - supports-color - '@typescript-eslint/scope-manager@8.32.0': + '@typescript-eslint/scope-manager@8.32.1': dependencies: - '@typescript-eslint/types': 8.32.0 - '@typescript-eslint/visitor-keys': 8.32.0 + '@typescript-eslint/types': 8.32.1 + '@typescript-eslint/visitor-keys': 8.32.1 - '@typescript-eslint/type-utils@8.32.0(eslint@9.26.0)(typescript@5.8.3)': + '@typescript-eslint/type-utils@8.32.1(eslint@9.26.0)(typescript@5.8.3)': dependencies: - '@typescript-eslint/typescript-estree': 8.32.0(typescript@5.8.3) - '@typescript-eslint/utils': 8.32.0(eslint@9.26.0)(typescript@5.8.3) + '@typescript-eslint/typescript-estree': 8.32.1(typescript@5.8.3) + '@typescript-eslint/utils': 8.32.1(eslint@9.26.0)(typescript@5.8.3) debug: 4.4.0 eslint: 9.26.0 ts-api-utils: 2.1.0(typescript@5.8.3) @@ -3197,36 +3201,36 @@ snapshots: transitivePeerDependencies: - supports-color - '@typescript-eslint/types@8.32.0': {} + '@typescript-eslint/types@8.32.1': {} - '@typescript-eslint/typescript-estree@8.32.0(typescript@5.8.3)': + '@typescript-eslint/typescript-estree@8.32.1(typescript@5.8.3)': dependencies: - '@typescript-eslint/types': 8.32.0 - '@typescript-eslint/visitor-keys': 8.32.0 + '@typescript-eslint/types': 8.32.1 + '@typescript-eslint/visitor-keys': 8.32.1 debug: 4.4.0 fast-glob: 3.3.3 is-glob: 4.0.3 minimatch: 9.0.5 - semver: 7.7.1 + semver: 7.7.2 ts-api-utils: 2.1.0(typescript@5.8.3) typescript: 5.8.3 transitivePeerDependencies: - supports-color - '@typescript-eslint/utils@8.32.0(eslint@9.26.0)(typescript@5.8.3)': + '@typescript-eslint/utils@8.32.1(eslint@9.26.0)(typescript@5.8.3)': dependencies: '@eslint-community/eslint-utils': 4.7.0(eslint@9.26.0) - '@typescript-eslint/scope-manager': 8.32.0 - '@typescript-eslint/types': 8.32.0 - '@typescript-eslint/typescript-estree': 8.32.0(typescript@5.8.3) + '@typescript-eslint/scope-manager': 8.32.1 + '@typescript-eslint/types': 8.32.1 + '@typescript-eslint/typescript-estree': 8.32.1(typescript@5.8.3) eslint: 9.26.0 typescript: 5.8.3 transitivePeerDependencies: - supports-color - '@typescript-eslint/visitor-keys@8.32.0': + '@typescript-eslint/visitor-keys@8.32.1': dependencies: - '@typescript-eslint/types': 8.32.0 + '@typescript-eslint/types': 8.32.1 eslint-visitor-keys: 4.2.0 '@webassemblyjs/ast@1.14.1': @@ -3494,7 +3498,7 @@ snapshots: browserslist@4.24.5: dependencies: caniuse-lite: 1.0.30001717 - electron-to-chromium: 1.5.151 + electron-to-chromium: 1.5.152 node-releases: 2.0.19 update-browserslist-db: 1.1.3(browserslist@4.24.5) @@ -3720,7 +3724,7 @@ snapshots: ee-first@1.1.1: {} - electron-to-chromium@1.5.151: {} + electron-to-chromium@1.5.152: {} emoji-regex@8.0.0: {} @@ -3819,7 +3823,7 @@ snapshots: '@humanfs/node': 0.16.6 '@humanwhocodes/module-importer': 1.0.1 '@humanwhocodes/retry': 0.4.3 - '@modelcontextprotocol/sdk': 1.11.1 + '@modelcontextprotocol/sdk': 1.11.2 '@types/estree': 1.0.7 '@types/json-schema': 7.0.15 ajv: 6.12.6 @@ -4006,7 +4010,7 @@ snapshots: process-warning: 5.0.0 rfdc: 1.4.1 secure-json-parse: 4.0.0 - semver: 7.7.1 + semver: 7.7.2 toad-cache: 3.7.0 fastq@1.19.1: @@ -4251,6 +4255,8 @@ snapshots: ignore@5.3.2: {} + ignore@7.0.4: {} + import-fresh@3.3.1: dependencies: parent-module: 1.0.1 @@ -4771,7 +4777,7 @@ snapshots: '@types/node-forge': 1.3.11 node-forge: 1.3.1 - semver@7.7.1: {} + semver@7.7.2: {} send@0.19.0: dependencies: diff --git a/src/client/dom/element.ts b/src/client/dom/element.ts index d3d7864..2d247fe 100644 --- a/src/client/dom/element.ts +++ b/src/client/dom/element.ts @@ -246,7 +246,7 @@ export default function (client: ScramjetClient, self: typeof window) { }, }); - client.Trap("Element.prototype.innerHTML", { + client.Trap(["Element.prototype.innerHTML", "Node.prototype.textContent"], { set(ctx, value: string) { let newval; if (ctx.this instanceof self.HTMLScriptElement) { @@ -339,7 +339,7 @@ export default function (client: ScramjetClient, self: typeof window) { }); client.Proxy("Text.prototype.appendData", { apply(ctx) { - if (ctx.this?.parentElement.tagName === "STYLE") { + if (ctx.this.parentElement?.tagName === "STYLE") { ctx.args[0] = rewriteCss(ctx.args[0], client.meta); } }, @@ -347,7 +347,7 @@ export default function (client: ScramjetClient, self: typeof window) { client.Proxy("Text.prototype.insertData", { apply(ctx) { - if (ctx.this?.parentElement.tagName === "STYLE") { + if (ctx.this.parentElement?.tagName === "STYLE") { ctx.args[1] = rewriteCss(ctx.args[1], client.meta); } }, @@ -355,7 +355,7 @@ export default function (client: ScramjetClient, self: typeof window) { client.Proxy("Text.prototype.insertData", { apply(ctx) { - if (ctx.this?.parentElement.tagName === "STYLE") { + if (ctx.this.parentElement?.tagName === "STYLE") { ctx.args[2] = rewriteCss(ctx.args[2], client.meta); } }, @@ -363,16 +363,19 @@ export default function (client: ScramjetClient, self: typeof window) { client.Trap(["Text.prototype.data", "Text.prototype.wholeText"], { get(ctx) { - if (ctx.this?.parentElement.tagName === "STYLE") { + if (ctx.this.parentElement?.tagName === "STYLE") { return unrewriteCss(ctx.get() as string); } }, set(ctx, v) { - if (ctx.this?.parentElement.tagName === "STYLE") { - ctx.set(rewriteCss(v as string, client.meta)); + if (ctx.this.parentElement?.tagName === "STYLE") { + return ctx.set(rewriteCss(v as string, client.meta)); } + + return ctx.set(v); }, }); + client.Trap( [ "HTMLIFrameElement.prototype.contentWindow", @@ -435,6 +438,7 @@ export default function (client: ScramjetClient, self: typeof window) { apply(ctx) { const doc = ctx.call(); if (doc) { + // we trap the contentDocument, this is really the scramjet version return ctx.return(ctx.this.contentDocument); } }, diff --git a/src/client/shared/requests/websocket.ts b/src/client/shared/requests/websocket.ts index eb6d3ed..6c9c67b 100644 --- a/src/client/shared/requests/websocket.ts +++ b/src/client/shared/requests/websocket.ts @@ -262,11 +262,16 @@ export default function (client: ScramjetClient, self: typeof globalThis) { }), readable: new ReadableStream({ start(controller) { - barews.addEventListener("message", (ev: MessageEvent) => { - const payload = ev.data; + barews.addEventListener("message", async (ev: MessageEvent) => { + let payload = ev.data; if (typeof payload === "string") { // DO NOTHING } else if ("byteLength" in payload) { + // arraybuffer, set the realms prototype so its recognized + Object.setPrototypeOf(payload, ArrayBuffer.prototype); + } else if ("arrayBuffer" in payload) { + // blob, convert to arraybuffer + payload = await payload.arrayBuffer(); Object.setPrototypeOf(payload, ArrayBuffer.prototype); } controller.enqueue(payload);