You do not have permission to use blocking webRequest listeners. Be sure to declare the webRequestBlocking permission in your manifest
回答 2
浏览 1648
2022-09-07
我试图用react js开发我的第一个chrome扩展。当我试图在chrome扩展中使用chrome.webRequest API封锁一个URL时,在错误页面显示了两个错误。
'webRequestBlocking' requires manifest version of 2 or lower.
Unchecked runtime.lastError: You do not have permission to use blocking webRequest listeners. Be sure to declare the webRequestBlocking permission in your manifest.
我在清单文件中声明了"webRequestBlocking"权限。以下是我的清单.json
{
"manifest_version": 3,
"name": "Chrome Extension",
"description": "First Extension",
"options_page": "options.html",
"background": {
"service_worker": "background.bundle.js",
"matches": [
"<all_urls>"
]
},
"action": {
"default_title": "Open Extension",
"default_icon": "icon-34.png"
},
"icons": {
"128": "icon-128.png"
},
"content_scripts": [
{
"matches": [
"http://*/*",
"https://*/*",
"<all_urls>"
],
"js": [
"contentScript.bundle.js"
],
"css": [
"content.styles.css"
]
}
],
"devtools_page": "devtools.html",
"web_accessible_resources": [
{
"resources": [
"content.styles.css",
"icon-128.png",
"icon-34.png"
],
"matches": []
}
],
"permissions": [
"activeTab",
"tabs",
"webRequest",
"webRequestBlocking"
],
"host_permissions": [
"<all_urls>"
]
}
这是我的background.js
chrome.webRequest.onBeforeRequest.addListener(
function(details) {
console.log(details);
return {cancel: true};
},
{urls: ["https://reactjs.org/"]},
["blocking"]
);
我试着去掉了webRequestBlocking,但也是一样的。谁能帮帮我,有什么办法能解决这个问题吗?
我们不能使用Manifest V2。谷歌Chrome扩展开发文档告知了这一点。" As of January 17, 2022 Chrome Web Store has stopped accepting new Manifest V2 extensions. We strongly recommend that new extensions target Manifest V3."
- Tharuka Dananjaya 2022-09-07
使用声明性的NetRequest来代替。
- wOxxOm 2022-09-07
2 个回答
#1楼
已采纳
得票数 2
该错误解释了它自己 'webRequestBlocking' requires manifest version of 2 or lower.
所以你不能在manifest 3中使用webRequestBlocking 。
但chrome给出了一个替代方案,即使用declarativeNetRequestWithHostAccess
API witch,通过指定声明性规则来阻止或修改网络请求,你可以查看这里以了解更多细节。
#2楼
得票数 0
你可以把manifest_version
改成2
,把webRequestBlocking
改成permissions
。
但在google chrome扩展开发文档中告知了这一点。 " As of January 17, 2022 Chrome Web Store has stopped accepting new Manifest V2 extensions. We strongly recommend that new extensions target Manifest V3."
- Tharuka Dananjaya 2022-09-07
但webRequestBlocking在v3中不工作。
- Saiful 2022-09-07