Firefox addon 如何在执行页面之前读取/截取页面上的JavaScript?

Firefox addon 如何在执行页面之前读取/截取页面上的JavaScript?,firefox-addon,Firefox Addon,我想截获location.reload()通过Firefox API或在加载/执行之前读取页面上的JS(远程和嵌入式),或通过任何其他可能的方式 例如: <head> <script> window.setTimeout(function() { location.reload(); }, 10000); </script> </head> setTimeout(函数(){location.reload();},

我想截获
location.reload()通过Firefox API或在加载/执行之前读取页面上的JS(远程和嵌入式),或通过任何其他可能的方式

例如:

<head>
    <script>
        window.setTimeout(function() { location.reload(); }, 10000);
    </script>
</head>

setTimeout(函数(){location.reload();},10000);
我在ScriptExecute
事件侦听器之前尝试过
(通过GreaseMonkey&
/@在文档开始时运行
),但在执行上述操作后会触发它

更新:
beforescriptexecute
在远程脚本上工作得很好,因为在发出请求之前会触发事件
beforescriptexecute
(但随后会触发脚本src而不是脚本内容)。根据给出的示例,如果脚本位于普通脚本标记内(而不是远程),则情况有所不同。启动
beforescriptexecute
并可以重写脚本内容,但此时已启动
窗口。setTimeout()
并正在执行。

启动
beforescriptexecute
应能正常工作。这是一项不油腻的活动:

你可以这样做:

document.addEventListener("beforescriptexecute", function(e) {

    src = e.target.src;
    content = e.target.text;

    if (src.search("i18n.js") > -1) {
        // Stop original script
        e.preventDefault();
        e.stopPropagation();
        window.jQuery(e.target).remove();

        var script = document.createElement('script');

        script.textContent = 'script you want';

        (document.head || document.documentElement).appendChild(script);
        script.onload = function() {
            this.parentNode.removeChild(this);
        }
      }

它在远程脚本上工作得很好,因为在发出请求之前会触发事件
beforescriptexecute
。根据给出的示例,如果脚本位于普通脚本标记内(而不是远程),则不完全相同。启动
beforescriptexecute
并可以重写脚本内容,但此时已启动
窗口。setTimeout()
并正在执行。噢,非常有趣!