我的目标:当我点击链接时,停止所有请求和浏览器不跳转到该链接。如果我点击链接http://tabbit.org/about,什么也不会发生,没有请求,没有跳转。
我已经通过“onBeforeRequest”监听器成功停止了请求,但浏览器仍然尝试导航到href的值,给我一个页面,上面写着“此网页被扩展程序阻止”
我尝试过:
var navigate = true;
var url = "http://tabbit.org/about"
/*
* Will prevent headers from being sent. Browser will still
* try to navigate to the clicked link, though.
*/
chrome.webRequest.onBeforeRequest.addListener(
function(details) {
navigate = false;
return {cancel: true} ;
},
// filters
{urls: [url]},
["blocking"]
);
// Somewhere in here is where I think navigation needs to be stopped.
chrome.webNavigation.onBeforeNavigate.addListener(
function(details) {
if (navigate == false) {
return false; // doesn't work.
//return {cancel: true}; // doesn't work.
};
},
{urls: [url]},
["blocking"]
)
我不想使用内容脚本,因为我希望对表单也能进行操作。 所以,如果对某个特定的URL进行GET或POST请求,我希望什么都不会发生。
我已经浏览了SO(和其他网站)寻找解决方案,但都没有成功。
onBeforeRequest
中重定向到 204 页面了吗? - rsanchez