【问题标题】:Runtime error on chrome extensionchrome 扩展上的运行时错误
【发布时间】:2018-07-23 06:27:50
【问题描述】:

前提:

尝试编写 一个非常简单的 chrome 扩展,作为测试,我想添加控制台日志记录以进行调试。但是,我不断收到此错误

在运行 webRequestInternal.addEventListener 时未选中 runtime.lastError您需要在清单文件中请求主机权限才能收到来自 webRequest 的请求的通知API。

已尝试:

我尝试添加所有我能找到的权限,但没有任何运气。谁能帮帮我!

清单文件:

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

【问题讨论】:

  • 尝试将这些 URL 从“optional_permissions”移动到“permissions”
  • "optional_permissions" 不会自动使用;您的扩展程序必须调用一个函数来要求用户允许这些权限,然后您才能使用它们。或者只是将它们放在“权限”中。 developer.chrome.com/apps/permissions

标签: javascript google-chrome google-chrome-extension


【解决方案1】:

我遇到了同样的问题,并出现了类似的错误消息。 ma​​nifest.json 中的一个简单更新解决了该问题。

permissions 数组如下所示:

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

permissions 中添加&lt;all_urls&gt; 将解决您的问题。

【讨论】:

  • 你拯救了我的一天!问候。
猜你喜欢
  • 2023-03-29
  • 1970-01-01
  • 2017-08-14
  • 2021-10-06
  • 1970-01-01
  • 1970-01-01
  • 2018-12-02
  • 1970-01-01
相关资源
最近更新 更多