gpt4 book ai didi

javascript - 在调用 htmlfile 窗口的原始 setTimeout 时“权限被拒绝”

转载 作者:行者123 更新时间:2023-11-30 05:53:34 25 4
gpt4 key购买 nike

我正在尝试覆盖 MSHTML 上的计时器方法(setTimeoutclearTimeoutsetIntervalclearInterval)例如,因此我可以跟踪已添加到 setTimeout/setInterval 的函数并阻止脚本退出,直到这些函数被调用或删除。

当在包装器 setTimeout 函数中调用原始 setTimeout 时,我收到了一个Permission denied 错误:

var window = new ActiveXObject('htmlfile').parentWindow.window;
var _setTimeout = window.setTimeout;

var timeouts = {};
setTimeout = function (code, ms, lang) {
//script fails here - Permission denied
var id = _setTimeout(code, ms, lang || 'javascript');
timeouts[id] = true;
return id;
};
setTimeout(function () {
window.alert('Timed function');
}, 1000);

var testTimeouts = function () {
var i;
for (i in timeouts) {
if (timeouts[i]) {return false;}
}
};
while (!testTimeouts()) {
WScript.Sleep(100);
}
window.alert('At end of script');

我可以在原始 setTimeout 被覆盖之前将代码传递给它:

window.setTimeout(function () {
window.alert('Timed function');
}, 1000);
WScript.Sleep(2500);
window.alert('At end of script');

保留原始上下文(如似乎已消失的答案中所建议的那样)不起作用:

window._setTimeout = window.setTimeout;

var timeouts = {};
window.setTimeout = function (code, ms, lang) {
var id = window._setTimeout(code, ms, lang || 'javascript');
timeouts[id] = true;
return id;
};
window.setTimeout(function () {
window.alert('Timed function');
}, 1000);

调用 window._setTimeout 失败,Object doesn't support this property or method

请注意,我正在运行 IE8、WinXP SP3、JScript 5.8。

最佳答案

为什么不从已存储的窗口中调用 setTimeout

var setTimeout;
var timeouts = {};
(function() {
var window = new ActiveXObject('htmlfile').parentWindow;
setTimeout = function(code, delay, lang){
var id = window.setTimeout(code, delay, lang || 'javascript');
timeouts[id] = true;
return id;
};
})();

关于javascript - 在调用 htmlfile 窗口的原始 setTimeout 时“权限被拒绝”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13331362/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com