开发者问题收集

chrome.webRequest 未定义

2020-12-24
1961

不确定我这里哪里出错了:

content.js

chrome.webRequest.onBeforeRequest.addListener(
  function(info) {
    console.log("URL intercepted: " + info.url);
  },
  // filters
  {
    urls: [
      "<all_urls>"
    ]
  },
  // extraInfoSpec
  ["blocking"]
);

manifest.json

{
  "name": "Color Changer",
  "author": "Microsoft Edge Extension Developer",
  "description": "Change the color of the body on learn.microsoft.com",
  "version": "1.0",
  "manifest_version": 2,
  "icons": {
    "25": "images/color-changer25.png",
    "48": "images/color-changer48.png"
  },
    "permissions": [
    "webRequest",
    "webRequestBlocking",
        "tabs",
        "notifications",
        "http://*/",
        "https://*/"
    ], 
  "browser_action": {
    "default_icon": {
      "20": "images/color-changer20.png",
      "40": "images/color-changer40.png"
    },
    "default_title": "Color Changer",
    "default_popup": "popup.html"
  },
  "content_scripts": [{
    "matches": [
        "<all_urls>"
    ],
    "js": [
      "js/jquery-3.5.1.min.js",
      "js/content.js"
    ],
    "run_at": "document_end"
  }],
  "background": {
    "scripts": ["js/background.js"],
    "persistent": true
  },
  "web_accessible_resources": [
    "css/*.css",
    "js/*.js",
    "html/*.html"
  ]
}

错误:

未捕获的 TypeError:无法读取未定义的属性“onBeforeRequest”

1个回答

内容脚本在其注入的页面上下文中运行。 chrome.* 对页面不可用。

Ouroborus
2020-12-24