Robeezy
Robeezy

Reputation: 2464

Chrome Extensions: You do not have permission to use blocking webRequest listeners

I am writing an extension and have this call in my background page:

chrome.webRequest.onBeforeRequest.addListener(function(details) {console.log(details)}, {urls: ["<all_urls>"]}, ["blocking"]);

However whenever I run it I get this error in the dev tools for the background page:

Error during webRequestInternal.addEventListener: You do not have permission to use blocking webRequest listeners. Be sure to declare the webRequestBlocking permission in your manifest. 

Even though my permissions in my manifest look like so:

"permissions": [
        "cookies",
        "http://*/*",
        "https://*/*",
        "tabs",
        "history",
        "webRequest",
        "webRequestBlocking"
    ]

What the heck is going on here? Here's the web request docs http://developer.chrome.com/stable/extensions/webRequest.html.

Upvotes: 4

Views: 8739

Answers (3)

Adham Zahran
Adham Zahran

Reputation: 2180

Going to manifest version 2 instead of 3 fixed this issue for me.

Upvotes: -2

Philipp Sch
Philipp Sch

Reputation: 348

I had a similar problem when I was writing my first Chrome extension: My solution was to remove the extension, fix the manifest.json and add the extension again. Just deactivating it and re-activating it won't do the trick.

I loaded the extension into Chrome and started to debug. When I found an error in the code, I deactivated the extension, fixed the bug an activated the extension again. This worked fine to fix code errors. But when I tried to use the webrequest module in a blocking fashion I always got "Error during webRequestInternal.addEventListener: You do not have permission to use blocking webRequest listeners. Be sure to declare the webRequestBlocking permission in your manifest.". No matter how I changed the manifest.json.

Upvotes: 1

Sudarshan
Sudarshan

Reputation: 18554

Works good for me with following code, why do you want to do it in a background page in specific?

Screen Shot

enter image description here

Manifest.json

{
"name":"My First App",
"description":"This is First App",
"version":"1",
"manifest_version":2,
"permissions": [
        "cookies",
        "http://*/*",
        "https://*/*",
        "tabs",
        "history",
        "webRequest",
        "webRequestBlocking"
    ],
"icons":{"16":"icon.jpg"},
"background":{
    "scripts": ["background.js"]
},
"browser_action":{
    "default_popup":"popup.html",
    "default_icon":"icon.jpg"
}
}

popup.html

<html>
<head>
<script src="popup.js"></script>
</head>
<body>
</body>
</html>

popup.js

chrome.webRequest.onBeforeRequest.addListener(function(details) {
console.log(details);
}, {urls: ["<all_urls>"]}, ["blocking"]);

Background.js

function doNothing(){
}

Upvotes: 2

Related Questions