Skip to content

Commit

Permalink
fix(sandbox): Avoid dom repeated agent insertion (#663)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhoushaw authored Mar 18, 2024
1 parent 3381742 commit 81ba4ad
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/browser-vm/src/dynamicNode/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 81ba4ad

Please sign in to comment.