Runtime error on chrome extension

核能气质少年 提交于 2019-12-24 10:48:00

问题


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"]);

回答1:


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.



来源:https://stackoverflow.com/questions/48757424/runtime-error-on-chrome-extension

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!