🐛 delete defineProperty to recover doc.currentScript (#2372)

This commit is contained in:
pshu 2023-01-12 17:31:07 +08:00 committed by GitHub
parent 2fc395e51f
commit 68d0e12bdb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 1 deletions

View File

@ -283,6 +283,7 @@ function getOverwrittenAppendChildOrInsertBefore(opts: {
const scopedGlobalVariables = speedySandbox ? trustedGlobals : []; const scopedGlobalVariables = speedySandbox ? trustedGlobals : [];
if (src) { if (src) {
let isRedfinedCurrentScript = false;
execScripts(null, [src], proxy, { execScripts(null, [src], proxy, {
fetch, fetch,
strictGlobal, strictGlobal,
@ -299,14 +300,23 @@ function getOverwrittenAppendChildOrInsertBefore(opts: {
}, },
configurable: true, configurable: true,
}); });
isRedfinedCurrentScript = true;
} }
}, },
success: () => { success: () => {
manualInvokeElementOnLoad(element); manualInvokeElementOnLoad(element);
if (isRedfinedCurrentScript) {
// @ts-ignore
delete document.currentScript;
}
element = null; element = null;
}, },
error: () => { error: () => {
manualInvokeElementOnError(element); manualInvokeElementOnError(element);
if (isRedfinedCurrentScript) {
// @ts-ignore
delete document.currentScript;
}
element = null; element = null;
}, },
}); });

View File

@ -161,7 +161,8 @@ export default class ProxySandbox implements SandBox {
} }
// the descriptor of global variables in whitelist before it been modified // 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; globalContext: typeof window;
constructor(name: string, globalContext = window) { constructor(name: string, globalContext = window) {