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);