Skip to content

Commit

Permalink
🐛 delete defineProperty to recover doc.currentScript (#2372)
Browse files Browse the repository at this point in the history
  • Loading branch information
stormslowly authored Jan 12, 2023
1 parent 2fc395e commit 68d0e12
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/sandbox/patchers/dynamicAppend/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ function getOverwrittenAppendChildOrInsertBefore(opts: {
const scopedGlobalVariables = speedySandbox ? trustedGlobals : [];

if (src) {
let isRedfinedCurrentScript = false;
execScripts(null, [src], proxy, {
fetch,
strictGlobal,
Expand All @@ -299,14 +300,23 @@ function getOverwrittenAppendChildOrInsertBefore(opts: {
},
configurable: true,
});
isRedfinedCurrentScript = true;
}
},
success: () => {
manualInvokeElementOnLoad(element);
if (isRedfinedCurrentScript) {
// @ts-ignore
delete document.currentScript;
}
element = null;
},
error: () => {
manualInvokeElementOnError(element);
if (isRedfinedCurrentScript) {
// @ts-ignore
delete document.currentScript;
}
element = null;
},
});
Expand Down
3 changes: 2 additions & 1 deletion src/sandbox/proxySandbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@ export default class ProxySandbox implements SandBox {
}

// the descriptor of global variables in whitelist before it been modified
globalWhitelistPrevDescriptor: { [p in typeof globalVariableWhiteList[number]]: PropertyDescriptor | undefined } = {};
globalWhitelistPrevDescriptor: { [p in (typeof globalVariableWhiteList)[number]]: PropertyDescriptor | undefined } =
{};
globalContext: typeof window;

constructor(name: string, globalContext = window) {
Expand Down

1 comment on commit 68d0e12

@vercel
Copy link

@vercel vercel bot commented on 68d0e12 Jan 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.