3

Premise:

Trying to write an incredibly simple chrome extension, and as a test, I wanted to add console logging for debugging. But, I keep getting this error

Unchecked runtime.lastError while running webRequestInternal.addEventListener: You need to request host permissions in the manifest file in order to be notified about requests from the webRequest API.

Attempted:

I have tried adding every permission I can find without any luck. Could someone please help me out!

Manifest File:

{
    "manifest_version": 2,
    "name": "test",
    "description": "testing app",
    "version": "1.0",
    "background": {
        "scripts": ["small.js"],
        "persistent": true
    },
    "permissions": ["webRequest", "webRequestBlocking", "tabs", "background", "storage"],
    "optional_permissions": ["http://*/*", "https://*/*", "<all_urls>"]
}

small.js

chrome.webRequest.onBeforeRequest.addListener(function(details) {
    if (details.method === "POST") {
        alert('here');
        console.log('logging here');

    } else if (details.method === "GET") {
        alert('there');
        console.log('logging there');
    }
}, {
    urls: ["<all_urls>"]
}, ["blocking", "requestBody"]);
AP.
  • 8,082
  • 2
  • 24
  • 33
razeal113
  • 451
  • 1
  • 4
  • 13
  • Try moving those URLs from "optional_permissions" to just "permissions" – Sidney Feb 12 '18 at 23:52
  • "optional_permissions" are not automatically used; your extension must call a function to ask the user to allow those permissions, then you can make use of them. Or just put them in "permissions". https://developer.chrome.com/apps/permissions – Sidney Feb 12 '18 at 23:53

1 Answers1

12

I was facing the same issue, with similar error message. A simple update in the manifest.json fixed the problem.

The permissions array looks like this:

 "permissions": [
    "alarms",
    "contextMenus",
    "storage",
    "notifications",
    "webRequest",
    "webRequestBlocking",
    "<all_urls>"
  ],

Adding the <all_urls> in permissions will fix your issue.

Abrar
  • 6,874
  • 9
  • 28
  • 41
  • For manifest v3 check out this answer https://stackoverflow.com/questions/66851301/permission-all-urls-is-unknown-or-url-pattern-is-malformed – Rafael Membrives Feb 07 '23 at 14:46