使用webRequest首先需要在manifest权限里声明,[“webRequest”,“webRequestBlocking”,"以及监控的地址,如监控所有则:*: //*/* "]
//插件监听拦截-图片
chrome.webRequest.onBeforeRequest.addListener (
function(details) {
// console.log(details);
// 回调返回一个对象,如果对象里得cancel为true则会拦截不继续请求
return {cancel: true};
},
//监听页面请求,你也可以通过*来匹配。urls地址,types请求资源类型
{urls:["*://*.baidu.com/*","*://*.bdstatic.com/*"], types: ["image"]},
["blocking"]
);