Problem Description
以下内容,TM和SC不一样
// ==UserScript==
// @name New Userscript
// @namespace http://tampermonkey.net/
// @version 2025-11-15
// @description try to take over the world!
// @author You
// @match https://*/*
// @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant GM_setValue
// ==/UserScript==
(function() {
'use strict';
console.log("window.__proto__", window.__proto__);
console.log("window.constructor", window.constructor);
// Your code here...
})();
9ced958
// 处理特殊关键字,不能穿越出沙盒,也不能被外部修改
for (const key of ["define", "module", "exports"]) {
mySandbox[key] = undefined;
}
这个还好
a1a868d
const sharedInitCopy = Object.create(Object.getPrototypeOf(global), {
->
const sharedInitCopy = Object.create(null, {
这个不行
被破坏后,导致下面commit
a4cefbc
// mySandbox 不进行with变量拦截
const unscopables: Record<PropertyKey, any> = {
this: true,
arguments: true,
// "await": true,
// "define": true,
// "module": true,
// "exports": true,
[Symbol.unscopables]: true,
};
删掉了 unscopables。原因是 toString() 的this穿透出去了,返回成了[object undefined]
正确是 返回[object Window]
这是由于 a1a868d 的破坏导致
64a08b4
同上,由于 被破坏了,导致 addEventListener 的 this 不正确
// ==UserScript==
// @name New Userscript TIYC-1
// @namespace https://docs.scriptcat.org/
// @version 0.1.0
// @description try to take over the world!
// @author You
// @match https://www.ign.com/wikis/starcraft/PC_Cheats
// @icon https://www.google.com/s2/favicons?sz=64&domain=www.ign.com
// @run-at document-end
// ==/UserScript==
(function () {
'use strict';
const urlchangeHandler = e => {
console.log(123);
}
console.log(this, window, window.addEventListener, urlchangeHandler);
window.addEventListener('pagetual_pushState', urlchangeHandler);
// Your code here...
})();
所以 descsCache.add(key); 被删掉
跟MDN有出入
EventTarget 和 Window 之間多了一層 WindowProperties
Problem Description
以下内容,TM和SC不一样
9ced958
这个还好
a1a868d
->
这个不行
被破坏后,导致下面commit
a4cefbc
删掉了
unscopables。原因是toString() 的this穿透出去了,返回成了[object undefined]正确是
返回[object Window]这是由于 a1a868d 的破坏导致
64a08b4
同上,由于 被破坏了,导致 addEventListener 的 this 不正确
所以
descsCache.add(key);被删掉跟MDN有出入
EventTarget 和 Window 之間多了一層 WindowProperties