2

Not sure where I'm going wrong here:

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"
  ]
}

Error:

Uncaught TypeError: Cannot read property 'onBeforeRequest' of undefined

TomSelleck
  • 6,706
  • 22
  • 82
  • 151

1 Answers1

3

Content scripts operate within the context of the page they are injected into. chrome.* isn't available to pages.

Ouroborus
  • 16,237
  • 4
  • 39
  • 62