谷歌浏览器扩展开发使用api(webRequest)的无效问题

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/...

阅读 4.2k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题