在全局上下文中停止window.location执行

use*_*858 5 google-chrome-extension firefox-addon-webextensions

我想在页面加载时停止执行window.location,如下所示:

<script type="text/javascript">
alert('Bid closed ');
window.location = '/index.html';
</script>
Run Code Online (Sandbox Code Playgroud)

我可以alert通过在manifest.json中替换alert函数来绕过消息document_start.但无法阻止window.location执行.

use*_*858 0

在我看来,答案就像一个数学难题。

在注入的脚本中,我刚刚放置了这段代码,它似乎可以工作:

window.alert =
                function (msg)
                    {
                       throw Error('hello');
                    }
Run Code Online (Sandbox Code Playgroud)

此异常导致浏览器跳过下一条语句window.location=