gpt4 book ai didi

javascript - chrome 扩展的运行时错误

转载 作者:行者123 更新时间:2023-11-30 11:23:55 24 4
gpt4 key购买 nike

前提:

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

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.

尝试:

我已经尝试添加我能找到的所有权限,但没有任何运气。有人可以帮帮我吗!

list 文件:

{
"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>"]
}

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

最佳答案

我遇到了同样的问题,有类似的错误信息。 ma​​nifest.json 中的一个简单更新解决了这个问题。

permissions数组看起来像这样:

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

添加 <all_urls>permissions将解决您的问题。

关于javascript - chrome 扩展的运行时错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48757424/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com