Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/364.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 无法读取属性';onBeforeRequest';未定义的_Javascript_Google Chrome_Google Chrome Extension_Webrequest - Fatal编程技术网

Javascript 无法读取属性';onBeforeRequest';未定义的

Javascript 无法读取属性';onBeforeRequest';未定义的,javascript,google-chrome,google-chrome-extension,webrequest,Javascript,Google Chrome,Google Chrome Extension,Webrequest,我看了其他有同样问题的问题,但找不到解决办法。 Mymanifest.json: { "background": { "scripts": [ "js/background.js" ], }, "description": "...", "icons": { "128": "icons/128.png", "16": "icons/16.png", "48": "icons/48.png" }, "manifes

我看了其他有同样问题的问题,但找不到解决办法。 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"

}
还有我的
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

我猜您在devtools的后台页面脚本中设置了断点?如果是这样,请将其移动到侦听器内的一行,以避免碰到错误。否则,请确保在上重新加载扩展chrome://extensions 页