From 93db66ebc820d6c0b68ec4dfa126404f143e8d4f Mon Sep 17 00:00:00 2001 From: velzie Date: Sat, 27 Jul 2024 12:00:35 -0400 Subject: [PATCH] feat: rewrite iframe.contentWindow --- src/client/client.ts | 8 ++++---- src/client/dom/element.ts | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/client/client.ts b/src/client/client.ts index 1ad58d7..e27ce32 100644 --- a/src/client/client.ts +++ b/src/client/client.ts @@ -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() { diff --git a/src/client/dom/element.ts b/src/client/dom/element.ts index bfd30ae..2b0f33d 100644 --- a/src/client/dom/element.ts +++ b/src/client/dom/element.ts @@ -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,