From 084f2cd78987e835a470488f25dd1e4e0c41cf89 Mon Sep 17 00:00:00 2001 From: velzie Date: Fri, 19 Jul 2024 14:24:29 -0400 Subject: [PATCH] hide document proxy from dom apis --- src/client/element.ts | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/client/element.ts b/src/client/element.ts index 29be462..536b904 100644 --- a/src/client/element.ts +++ b/src/client/element.ts @@ -1,3 +1,4 @@ +import { client } from "."; import { decodeUrl } from "../shared/rewriters/url"; import { encodeUrl, @@ -138,10 +139,19 @@ MutationObserver.prototype.observe = new Proxy( } ); -document.createTreeWalker = new Proxy(document.createTreeWalker, { - apply(target, thisArg, argArray) { - if (argArray[0] === documentProxy) argArray[0] = document; +for (const target of [Node.prototype, document]) { + for (const prop in target) { + try { + if (typeof target[prop] === "function") { + client.Proxy(target, prop, { + apply(ctx) { + for (const i in ctx.args) { + if (ctx.args[i] === documentProxy) ctx.args[i] = document; + } + }, + }); + } + } catch (e) { } + } +} - return Reflect.apply(target, thisArg, argArray); - }, -});