From c2a7590666d6e03789a07ac132540f584a08ea47 Mon Sep 17 00:00:00 2001 From: Kuitos Date: Tue, 25 May 2021 17:49:26 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20should=20not=20change=20currentS?= =?UTF-8?q?cript=20if=20it=20not=20configurable=20(#1470)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/sandbox/patchers/dynamicAppend/common.ts | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/sandbox/patchers/dynamicAppend/common.ts b/src/sandbox/patchers/dynamicAppend/common.ts index 42c117d..969b76b 100644 --- a/src/sandbox/patchers/dynamicAppend/common.ts +++ b/src/sandbox/patchers/dynamicAppend/common.ts @@ -219,12 +219,18 @@ function getOverwrittenAppendChildOrInsertBefore(opts: { fetch, strictGlobal, beforeExec: () => { - Object.defineProperty(document, 'currentScript', { - get(): any { - return element; - }, - configurable: true, - }); + const isCurrentScriptConfigurable = () => { + const descriptor = Object.getOwnPropertyDescriptor(document, 'currentScript'); + return !descriptor || descriptor.configurable; + }; + if (isCurrentScriptConfigurable()) { + Object.defineProperty(document, 'currentScript', { + get(): any { + return element; + }, + configurable: true, + }); + } }, success: () => { manualInvokeElementOnLoad(element);