This code doesn't work:

chrome.webRequest.onBeforeRequest.addListener(function(details){

    console.log(details);

},{urls:["<all_urls>"]},['blocking']);

This code does work:

chrome.webRequest.onBeforeRequest.addListener(function(details){

    console.log(details);

},{urls:["<all_urls>"]});

The question - Why the first code won't work?

有帮助吗?

解决方案

The only difference between your first and second code snippet is the "blocking" extraInfoSpec.
This suggests that you have not declared the required webRequestBlocking permission in manifest.json. If you want to use "blocking", then you have to add it to manifest.json, like this:

{
    ...
    "permissions": [
        "webRequest",
        "webRequestBlocking",
        "webRequest"
    ],
    ...
}

This is a bug, and it has been reported at https://code.google.com/p/chromium/issues/detail?id=311511 ("Missing webRequestBlocking permission gives no warning to developers").

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top