質問

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