我看了同样问题的其他问题,但我找不到解决方案。
我的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'
可能是什么问题?
答案 0 :(得分:1)
你的manifest.json可能是原因。
它有“权限”的重复条目。尝试删除第二个。
"permissions": [ "webRequest", "webRequestBlocking", "https://www.youtube.com/*" ],
"permissions": [ "https://www.youtube.com/*" ], // remove this one