fix: function proxy and frame elements

This commit is contained in:
Percs 2024-12-05 04:17:50 +00:00 committed by GitHub
parent e5dff7f6fc
commit 06583fb0b2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 60 additions and 19 deletions

View file

@ -27,7 +27,7 @@
],
"keywords": [],
"author": "",
"license": "ISC",
"license": "MIT",
"devDependencies": {
"@eslint/eslintrc": "^3.2.0",
"@eslint/js": "^9.16.0",

View file

@ -263,6 +263,57 @@ export default function (client: ScramjetClient, self: typeof window) {
},
});
client.Trap("HTMLFrameElement.prototype.contentWindow", {
get(ctx) {
const realwin = ctx.get() as Window;
if (!realwin) return realwin;
if (SCRAMJETCLIENT in realwin) {
return realwin[SCRAMJETCLIENT].globalProxy;
} else {
// hook the iframe
const newclient = new ScramjetClient(realwin);
newclient.hook();
return newclient.globalProxy;
}
},
});
client.Trap("HTMLFrameElement.prototype.contentDocument", {
get(ctx) {
const contentwindow =
client.descriptors["HTMLFrameElement.prototype.contentWindow"].get;
const realwin = contentwindow.apply(ctx.this);
if (!realwin) return realwin;
if (SCRAMJETCLIENT in realwin) {
return realwin[SCRAMJETCLIENT].documentProxy;
} else {
const newclient = new ScramjetClient(realwin);
newclient.hook();
return newclient.documentProxy;
}
},
});
client.Proxy(
[
"HTMLIFrameElement.prototype.getSVGDocument",
"HTMLObjectElement.prototype.getSVGDocument",
"HTMLEmbedElement.prototype.getSVGDocument",
],
{
apply(ctx) {
const doc = ctx.call();
if (doc) {
ctx.return(ctx.this.contentDocument);
}
},
}
);
client.Trap("TreeWalker.prototype.currentNode", {
get(ctx) {
return ctx.get();
@ -312,22 +363,6 @@ export default function (client: ScramjetClient, self: typeof window) {
}
);
client.Proxy(
[
"HTMLIFrameElement.prototype.getSVGDocument",
"HTMLObjectElement.prototype.getSVGDocument",
"HTMLEmbedElement.prototype.getSVGDocument",
],
{
apply(ctx) {
const doc = ctx.call();
if (doc) {
ctx.return(ctx.this.contentDocument);
}
},
}
);
client.Proxy("Node.prototype.getRootNode", {
apply(ctx) {
const n = ctx.call() as Node;

View file

@ -10,7 +10,12 @@ function rewriteFunction(ctx: ProxyCtx, client: ScramjetClient) {
export default function (client: ScramjetClient, _self: Self) {
const handler: Proxy = {
apply(ctx) {
apply(ctx: ProxyCtx) {
if ((ctx.fn as any).alreadyProxied) {
debugger;
throw new Error("blah slop");
}
(ctx.fn as any).alreadyProxied = true;
rewriteFunction(ctx, client);
},
construct(ctx) {
@ -19,7 +24,7 @@ export default function (client: ScramjetClient, _self: Self) {
};
client.Proxy("Function", handler);
/*
// god i love javascript
client.RawProxy(function () {}.constructor.prototype, "constructor", handler);
client.RawProxy(
@ -37,4 +42,5 @@ export default function (client: ScramjetClient, _self: Self) {
"constructor",
handler
);
*/
}