From e942f5549e53202d16a720d062cad236812f3205 Mon Sep 17 00:00:00 2001 From: velzie Date: Mon, 14 Oct 2024 10:38:55 -0400 Subject: [PATCH] proxy for window[0] --- src/client/global.ts | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/client/global.ts b/src/client/global.ts index 8502eb9..69268a3 100644 --- a/src/client/global.ts +++ b/src/client/global.ts @@ -1,4 +1,6 @@ // import { encodeUrl } from "../shared"; +import { iswindow } from "."; +import { SCRAMJETCLIENT } from "../symbols"; import { ScramjetClient } from "./client"; // import { config } from "../shared"; import { getOwnPropertyDescriptorHandler } from "./helpers"; @@ -25,6 +27,28 @@ export function createGlobalProxy( get(target, prop) { const value = Reflect.get(target, prop); + if ( + iswindow && + (typeof prop === "string" || typeof prop === "number") && + !isNaN(Number(prop)) && + value + ) { + const win: Self = value.self; + // indexing into window gives you the contentWindow of the subframes for some reason + // you can't *set* it so this should always be the right value + if (SCRAMJETCLIENT in win) { + // then we've already hooked this frame and we can just send over its proxy + return win[SCRAMJETCLIENT].globalProxy; + } else { + // this can happen if it's an about:blank iframe that we've never gotten the chance to inject into + // just make a new client for it and inject + const newclient = new ScramjetClient(win); + newclient.hook(); + + return newclient.globalProxy; + } + } + if (typeof prop === "string" && UNSAFE_GLOBALS.includes(prop)) return client.wrapfn(value);