bg.js内容如下
console.log("background")
chrome.webRequest.onBeforeRequest.addListener(
function(details) {
return {cancel: details.url.indexOf("://www.baidu.com/") != -1};
},
{urls: ["<all_urls>"]},
["blocking"]
);
manifest.json内容如下
{
"manifest_version":2,
"name":"one-click hello_world",
"description":"my first chrome extension-background",
"version":"1.0",
"permissions":[
"webRequest"
"webRequestBlocking"
"tabs",
"https://*/*",
"http://*/*"
],
"background": {
"scripts": ["bg.js"],
"persistent": false
}
}
最终没有阻止向百度的请求,而且console.log的内容也没有在控制台显示
贴上此api的官方说明文档https://developer.chrome.com/...