Reputation: 500
I looked at other questions with the same problem, but I couldn't found a solution.
My 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"
}
and my 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"]);
I getting this Error:
Uncaught TypeError: Cannot read property 'onBeforeRequest' of undefined
What could be the problem?
Upvotes: 3
Views: 4426
Reputation: 701
Your manifest.json may be the reason.
It has duplicate entries for "permissions". Try to remove the second one.
"permissions": [ "webRequest", "webRequestBlocking", "https://www.youtube.com/*" ],
"permissions": [ "https://www.youtube.com/*" ], // remove this one
Upvotes: 1