From 2288dae8d5589c97a8d2b1983fb9b97df05df04e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E4=B8=80=E4=B9=8B?= Date: Mon, 26 Feb 2024 11:51:52 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20=E4=BF=AE=E5=A4=8DtoString.call(?= =?UTF-8?q?window)=E8=BF=94=E5=9B=9E=E5=86=85=E5=AE=B9=E4=B8=8D=E6=AD=A3?= =?UTF-8?q?=E7=A1=AE=20#260?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- example/{usersubscribe.js => usersubscribe.user.sub.js} | 0 src/runtime/content/utils.test.ts | 6 +++++- src/runtime/content/utils.ts | 3 +++ 3 files changed, 8 insertions(+), 1 deletion(-) rename example/{usersubscribe.js => usersubscribe.user.sub.js} (100%) diff --git a/example/usersubscribe.js b/example/usersubscribe.user.sub.js similarity index 100% rename from example/usersubscribe.js rename to example/usersubscribe.user.sub.js diff --git a/src/runtime/content/utils.test.ts b/src/runtime/content/utils.test.ts index e43b1fa8..507b8bd4 100644 --- a/src/runtime/content/utils.test.ts +++ b/src/runtime/content/utils.test.ts @@ -55,12 +55,16 @@ describe("兼容问题", () => { }); }); -// 允许往global写入Symbol属性,影响内容: https://bbs.tampermonkey.net.cn/thread-5509-1-1.html describe("Symbol", () => { const _this = proxyContext({}, {}); + // 允许往global写入Symbol属性,影响内容: https://bbs.tampermonkey.net.cn/thread-5509-1-1.html it("Symbol", () => { const s = Symbol("test"); _this[s] = "ok"; expect(_this[s]).toEqual("ok"); }); + // toString.call(window)返回的是'[object Object]'而不是'[object Window]',影响内容: https://github.com/scriptscat/scriptcat/issues/260 + it("Window", () => { + expect(toString.call(_this)).toEqual("[object Window]"); + }); }); diff --git a/src/runtime/content/utils.ts b/src/runtime/content/utils.ts index 99397073..0b3d2781 100644 --- a/src/runtime/content/utils.ts +++ b/src/runtime/content/utils.ts @@ -229,6 +229,8 @@ export function proxyContext( } } else if (name === Symbol.unscopables) { return unscopables; + } else if (name === Symbol.toStringTag) { + return name; } } return undefined; @@ -317,6 +319,7 @@ export function proxyContext( } }, }); + proxy[Symbol.toStringTag] = "Window"; return proxy; }