diff --git a/src/client/postmessage.ts b/src/client/postmessage.ts index b26e4d4..bf9c8dd 100644 --- a/src/client/postmessage.ts +++ b/src/client/postmessage.ts @@ -1,6 +1,6 @@ window.postMessage = new Proxy(window.postMessage, { - apply(target, thisArg, argArray) { - if (typeof argArray[1] === "string") argArray[1] = "*" - Reflect.apply(target, thisArg, argArray); - } + apply(target, thisArg, argArray) { + if (typeof argArray[1] === "string") argArray[1] = "*"; + Reflect.apply(target, thisArg, argArray); + }, }); diff --git a/src/client/window.ts b/src/client/window.ts index dc75359..edb2e69 100644 --- a/src/client/window.ts +++ b/src/client/window.ts @@ -77,3 +77,27 @@ export const documentProxy = new Proxy(document, { return Reflect.set(target, prop, newValue); }, }); + +Function.prototype.apply = new Proxy(Function.prototype.apply, { + apply(target, thisArg, argArray) { + if (argArray[0] === windowProxy) { + argArray[0] = window; + } else if (argArray[0] === documentProxy) { + argArray[0] = document; + } + + return Reflect.apply(target, thisArg, argArray); + }, +}); + +Function.prototype.call = new Proxy(Function.prototype.call, { + apply(target, thisArg, argArray) { + if (argArray[0] === windowProxy) { + argArray[0] = window; + } else if (argArray[0] === documentProxy) { + argArray[0] = document; + } + + return Reflect.apply(target, thisArg, argArray); + }, +}); diff --git a/src/shared/rewriters/js.ts b/src/shared/rewriters/js.ts index a5c99ef..865caf2 100644 --- a/src/shared/rewriters/js.ts +++ b/src/shared/rewriters/js.ts @@ -17,7 +17,7 @@ initSync( init(); -Error.stackTraceLimit = 50 +Error.stackTraceLimit = 50; global.rws = rewriteJs; export function rewriteJs(js: string | ArrayBuffer, origin?: URL) {