feat: rewrite iframe.contentWindow

This commit is contained in:
velzie 2024-07-27 12:00:35 -04:00
parent 506d99f9b6
commit 93db66ebc8
No known key found for this signature in database
GPG key ID: 048413F95F0DDE1F
2 changed files with 20 additions and 4 deletions

View file

@ -48,13 +48,13 @@ export class ScramjetClient {
constructor(public global: typeof globalThis) {
if ("document" in self) {
this.documentProxy = createDocumentProxy(this, self);
this.documentProxy = createDocumentProxy(this, global);
}
this.locationProxy = createLocationProxy(this, self);
this.windowProxy = createWindowProxy(this, self);
this.locationProxy = createLocationProxy(this, global);
this.windowProxy = createWindowProxy(this, global);
self[ScramjetClient.SCRAMJET] = this;
global[ScramjetClient.SCRAMJET] = this;
}
hook() {

View file

@ -140,6 +140,22 @@ export default function (client: ScramjetClient, self: typeof window) {
},
});
client.Trap("HTMLIFrameElement.prototype.contentWindow", {
get(ctx) {
const realwin = ctx.get() as Window;
if (ScramjetClient.SCRAMJET in realwin.self) {
return realwin.self[ScramjetClient.SCRAMJET].windowProxy;
} else {
// hook the iframe
const newclient = new ScramjetClient(realwin.self);
newclient.hook();
return newclient.windowProxy;
}
},
});
for (const target of [
self.Node.prototype,
self.MutationObserver.prototype,