我看了同样问题的其他问题,但找不到解决方案。
我的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"]);
我收到此错误:
未捕获的TypeError:无法读取未定义的属性'onBeforeRequest'
可能是什么问题呢?
最佳答案
您的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/