fix: 插件沙箱不再覆盖 window - 用真实 globalThis 替代 fakeGlobal,修复 window.location.href undefined

This commit is contained in:
auto-bot
2026-06-14 00:42:00 +00:00
parent 9062a4fe5b
commit fa7f6fec15

View File

@@ -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 等