mirror of
https://github.com/MercuryWorkshop/scramjet.git
synced 2025-05-13 06:20:02 -04:00
feat: start proxying more css things
This commit is contained in:
parent
02ae723a41
commit
375c54d5ed
7 changed files with 761 additions and 312 deletions
18
package.json
18
package.json
|
@ -32,7 +32,7 @@
|
|||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"@eslint/eslintrc": "^3.3.1",
|
||||
"@eslint/js": "^9.25.1",
|
||||
"@eslint/js": "^9.26.0",
|
||||
"@estruyf/github-actions-reporter": "^1.10.0",
|
||||
"@fastify/static": "^8.1.1",
|
||||
"@mercuryworkshop/bare-as-module3": "^2.2.5",
|
||||
|
@ -41,17 +41,17 @@
|
|||
"@mercuryworkshop/wisp-js": "^0.3.3",
|
||||
"@nebula-services/bare-server-node": "^2.0.4",
|
||||
"@playwright/test": "^1.52.0",
|
||||
"@rsdoctor/rspack-plugin": "^1.0.2",
|
||||
"@rspack/cli": "^1.3.8",
|
||||
"@rspack/core": "^1.3.8",
|
||||
"@rsdoctor/rspack-plugin": "^1.1.2",
|
||||
"@rspack/cli": "^1.3.9",
|
||||
"@rspack/core": "^1.3.9",
|
||||
"@types/eslint": "^9.6.1",
|
||||
"@types/estree": "^1.0.7",
|
||||
"@types/node": "^22.15.3",
|
||||
"@types/serviceworker": "^0.0.132",
|
||||
"@typescript-eslint/eslint-plugin": "^8.31.1",
|
||||
"@typescript-eslint/parser": "^8.31.1",
|
||||
"@types/node": "^22.15.17",
|
||||
"@types/serviceworker": "^0.0.134",
|
||||
"@typescript-eslint/eslint-plugin": "^8.32.0",
|
||||
"@typescript-eslint/parser": "^8.32.0",
|
||||
"dotenv": "^16.5.0",
|
||||
"eslint": "^9.25.1",
|
||||
"eslint": "^9.26.0",
|
||||
"fastify": "^5.3.2",
|
||||
"playwright": "^1.52.0",
|
||||
"prettier": "^3.5.3",
|
||||
|
|
945
pnpm-lock.yaml
generated
945
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load diff
|
@ -25,6 +25,26 @@ export default function (client: ScramjetClient) {
|
|||
return unrewriteCss(ctx.get());
|
||||
},
|
||||
});
|
||||
client.Proxy("CSSStyleSheet.prototype.insertRule", {
|
||||
apply(ctx) {
|
||||
ctx.args[0] = rewriteCss(ctx.args[0], client.meta);
|
||||
},
|
||||
});
|
||||
client.Trap("CSSRule.prototype.cssText", {
|
||||
set(ctx, value: string) {
|
||||
ctx.set(rewriteCss(value, client.meta));
|
||||
},
|
||||
get(ctx) {
|
||||
return unrewriteCss(ctx.get());
|
||||
},
|
||||
});
|
||||
|
||||
client.Proxy(["CSSStyleValue.parse", "CSSStyleValue.parseAll"], {
|
||||
apply(ctx) {
|
||||
if (!ctx.args[1]) return;
|
||||
ctx.args[1] = rewriteCss(ctx.args[1], client.meta);
|
||||
},
|
||||
});
|
||||
|
||||
client.Trap("HTMLElement.prototype.style", {
|
||||
get(ctx) {
|
||||
|
|
|
@ -2,6 +2,18 @@ import { rewriteHtml } from "../../shared";
|
|||
import { ScramjetClient } from "../client";
|
||||
|
||||
export default function (client: ScramjetClient, _self: Self) {
|
||||
client.Proxy(
|
||||
["Document.prototype.querySelector", "Document.prototype.querySelectorAll"],
|
||||
{
|
||||
apply(ctx) {
|
||||
ctx.args[0] = (ctx.args[0] as string).replace(
|
||||
/((?:^|\s)\b\w+\[(?:src|href|data-href))[\^]?(=['"]?(?:https?[:])?\/\/)/,
|
||||
"$1*$2"
|
||||
);
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
client.Proxy("Document.prototype.write", {
|
||||
apply(ctx) {
|
||||
if (ctx.args[0])
|
||||
|
|
|
@ -1,8 +1,13 @@
|
|||
import { SCRAMJETCLIENT } from "../../symbols";
|
||||
import { ScramjetClient } from "../client";
|
||||
import { nativeGetOwnPropertyDescriptor } from "../natives";
|
||||
import { unrewriteUrl, htmlRules, unrewriteHtml } from "../../shared";
|
||||
import { rewriteCss, rewriteHtml, rewriteJs } from "../../shared";
|
||||
import {
|
||||
unrewriteUrl,
|
||||
rewriteUrl,
|
||||
htmlRules,
|
||||
unrewriteHtml,
|
||||
} from "../../shared";
|
||||
import { unrewriteCss, rewriteCss, rewriteHtml, rewriteJs } from "../../shared";
|
||||
|
||||
const encoder = new TextEncoder();
|
||||
function bytesToBase64(bytes: Uint8Array) {
|
||||
|
@ -328,6 +333,48 @@ export default function (client: ScramjetClient, self: typeof window) {
|
|||
},
|
||||
});
|
||||
|
||||
client.Proxy("Audio", {
|
||||
construct(ctx) {
|
||||
ctx.args[0] = rewriteUrl(ctx.args[0], client.meta);
|
||||
},
|
||||
});
|
||||
|
||||
client.Proxy("Text.prototype.appendData", {
|
||||
apply(ctx) {
|
||||
if (ctx.this?.parentElement.tagName === "STYLE") {
|
||||
ctx.args[0] = rewriteCss(ctx.args[0], client.meta);
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
client.Proxy("Text.prototype.insertData", {
|
||||
apply(ctx) {
|
||||
if (ctx.this?.parentElement.tagName === "STYLE") {
|
||||
ctx.args[1] = rewriteCss(ctx.args[1], client.meta);
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
client.Proxy("Text.prototype.insertData", {
|
||||
apply(ctx) {
|
||||
if (ctx.this?.parentElement.tagName === "STYLE") {
|
||||
ctx.args[2] = rewriteCss(ctx.args[2], client.meta);
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
client.Trap(["Text.prototype.data", "Text.prototype.wholeText"], {
|
||||
get(ctx) {
|
||||
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));
|
||||
}
|
||||
},
|
||||
});
|
||||
client.Trap(
|
||||
[
|
||||
"HTMLIFrameElement.prototype.contentWindow",
|
||||
|
@ -454,7 +501,6 @@ export default function (client: ScramjetClient, self: typeof window) {
|
|||
},
|
||||
}
|
||||
);
|
||||
|
||||
client.Proxy("Node.prototype.getRootNode", {
|
||||
apply(ctx) {
|
||||
const n = ctx.call() as Node;
|
||||
|
|
15
src/client/dom/protocol.ts
Normal file
15
src/client/dom/protocol.ts
Normal file
|
@ -0,0 +1,15 @@
|
|||
import { rewriteUrl } from "../../shared";
|
||||
import { ScramjetClient } from "../client";
|
||||
|
||||
export default function (client: ScramjetClient, self: Self) {
|
||||
client.Proxy("Navigator.prototype.registerProtocolHandler", {
|
||||
apply(ctx) {
|
||||
ctx.args[1] = rewriteUrl(ctx.args[1], client.meta);
|
||||
},
|
||||
});
|
||||
client.Proxy("Navigator.prototype.unregisterProtocolHandler", {
|
||||
apply(ctx) {
|
||||
ctx.args[1] = rewriteUrl(ctx.args[1], client.meta);
|
||||
},
|
||||
});
|
||||
}
|
|
@ -53,6 +53,17 @@ export default function (client: ScramjetClient, self: Self) {
|
|||
return unrewriteUrl(this.newURL);
|
||||
},
|
||||
},
|
||||
storage: {
|
||||
_init() {
|
||||
return this.key.startsWith(client.url.host + "@");
|
||||
},
|
||||
key() {
|
||||
return this.key.substring(this.key.indexOf("@") + 1);
|
||||
},
|
||||
url() {
|
||||
return unrewriteUrl(this.url);
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
function wraplistener(listener: (...args: any) => any) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue