我正在开发一个 chrome 扩展程序,在扩展程序的一部分中,我需要检测重定向并询问用户他/她是否希望继续。我尝试使用 chrome 的 webRequest API 来执行此操作,但它似乎无法正常工作,尽管我确定我的语法是正确的。相关代码如下:
chrome.webRequest.onBeforeRedirect.addListener(function (details) {
if(details.frameId == 0){
if (confirm("This link is a redirect. Do you want to continue?")){
/* do nothing and let them redirect */
}
else {
/* stop the redirect from happening */
return {cancel: true};
}
}
}, {urls: ["<all_urls>"], types: ["main_frame"]}, ["blocking"]);
为什么方法没有正确阻塞?
最佳答案
根据 official guide , 你不能取消重定向
onBeforeRedirect
Fires when a redirect is about to be executed. A redirection can be triggered by an HTTP response code or by an extension. This event is informational and handled asynchronously. It does not allow you to modify or cancel the request.
关于javascript - chrome.webRequest.onBeforeRedirect 不停止重定向?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38270321/