【发布时间】: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