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

@ -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;