From 81ba4ad82b0c48735aac30d5a11f0fcb6da0f47d Mon Sep 17 00:00:00 2001 From: Zhou xiao Date: Mon, 18 Mar 2024 15:46:14 +0800 Subject: [PATCH] fix(sandbox): Avoid dom repeated agent insertion (#663) --- packages/browser-vm/src/dynamicNode/index.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/browser-vm/src/dynamicNode/index.ts b/packages/browser-vm/src/dynamicNode/index.ts index a72aa6f78..2f73b116d 100644 --- a/packages/browser-vm/src/dynamicNode/index.ts +++ b/packages/browser-vm/src/dynamicNode/index.ts @@ -122,13 +122,17 @@ export function makeElInjector(sandboxConfig: SandboxOptions) { ) => { for (const name of methods) { const fn = window.Element.prototype[name]; - if (typeof fn !== 'function' || fn[__domWrapper__]) { + const symbolProxyName = Symbol.for(name + '_proxy'); + const proxyFlag = window.Element.prototype[symbolProxyName]; + if (typeof fn !== 'function' || fn[__domWrapper__] || proxyFlag) { continue; } rawElementMethods[name] = fn; const wrapper = builder(fn, name); wrapper[__domWrapper__] = true; window.Element.prototype[name] = wrapper; + // Avoid being re-mediated by the function + window.Element.prototype[symbolProxyName] = true; } }; rewrite(mountElementMethods, injector);