gpt4 book ai didi

javascript - 无法读取未定义的属性 'onBeforeRequest'

转载 作者:行者123 更新时间:2023-11-30 21:16:04 25 4
gpt4 key购买 nike

我看了其他有同样问题的问题,但找不到解决方案。我的 manifest.json:

{
"background": {
"scripts": [ "js/background.js" ],
},
"description": "...",
"icons": {
"128": "icons/128.png",
"16": "icons/16.png",
"48": "icons/48.png"
},
"manifest_version": 2,
"name": "Name it!",
"offline_enabled": false,
"permissions": [ "webRequest", "webRequestBlocking", "https://www.youtube.com/*" ],
"permissions": [ "https://www.youtube.com/*" ],
"version": "1.0"

}

和我的background.js:

chrome.webRequest.onBeforeRequest.addListener(
function(details) {
var idid = details.url;
var vid = idid.split("watch?v=");
var akk = vid[1];
if (akk.includes("&") && akk.includes("=")) {
akk = akk.split("&")[0];
}
var xhr = new XMLHttpRequest();
xhr.open("GET", "https://www.youtube.com/feeds/videos.xml?channel_id=xxx", false);
xhr.send();
var result = xhr.responseText;
if(result.includes(akk)) {
redirectUrl : "chrome-extension://"+window.location.hostname+"/html/block.html"
}
},
{urls: ["https://www.youtube.com/*"]},
["blocking"]);

我收到这个错误:

Uncaught TypeError: Cannot read property 'onBeforeRequest' of undefined

可能是什么问题?

最佳答案

您的 manifest.json 可能是原因。

它有重复的“权限”条目。尝试删除第二个。

 "permissions": [ "webRequest", "webRequestBlocking", "https://www.youtube.com/*" ],
"permissions": [ "https://www.youtube.com/*" ], // remove this one

关于javascript - 无法读取未定义的属性 'onBeforeRequest',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45669284/

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