From fa7f6fec15e33c7784615cc6df12a70511c261fd Mon Sep 17 00:00:00 2001 From: auto-bot Date: Sun, 14 Jun 2026 00:42:00 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=8F=92=E4=BB=B6=E6=B2=99=E7=AE=B1?= =?UTF-8?q?=E4=B8=8D=E5=86=8D=E8=A6=86=E7=9B=96=20window=20-=20=E7=94=A8?= =?UTF-8?q?=E7=9C=9F=E5=AE=9E=20globalThis=20=E6=9B=BF=E4=BB=A3=20fakeGlob?= =?UTF-8?q?al=EF=BC=8C=E4=BF=AE=E5=A4=8D=20window.location.href=20undefine?= =?UTF-8?q?d?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/pluginManager.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/plugins/pluginManager.ts b/src/plugins/pluginManager.ts index 02ed31d..f03760c 100644 --- a/src/plugins/pluginManager.ts +++ b/src/plugins/pluginManager.ts @@ -516,6 +516,11 @@ export class PluginManager { exports: moduleObj.exports, __dirname: '/', __filename: '/plugin.js', + // Node 全局(alias 到浏览器真实全局,以保持 window.location.href 正常工作) + global: globalThis, + globalThis: globalThis, + self: globalThis, + root: globalThis, console, setTimeout: setTimeout as any, clearTimeout, @@ -552,11 +557,9 @@ export class PluginManager { crypto: (globalThis as any).crypto, performance: (globalThis as any).performance, }; - fakeGlobal.self = fakeGlobal; - fakeGlobal.window = fakeGlobal; - fakeGlobal.global = fakeGlobal; - fakeGlobal.globalThis = fakeGlobal; - fakeGlobal.root = fakeGlobal; + // 注意:不再覆盖 window / location / document / navigator + // 让 with(fakeGlobal) 在查找这些未覆盖变量时自动回落到浏览器真实全局作用域 + // 确保 window.location.href / document.cookie / navigator.userAgent 等正常工作 // 用 with(fakeGlobal) 包裹代码,让所有嵌套层都能访问 // require / module / exports / process / Buffer / zlib / http 等