2

Manifest.json

{
  "name": "Getting Started Example",
  "description": "Build an Extension!",
  "version": "1.0",
  "manifest_version": 3,
  "background": {
    "service_worker": "background.js"
  },
  "action": {
    "default_popup": "popup.html",
    "default_icon": {
      "32": "icons/32x32.png"
    }
  },
  "content_scripts": [
    {
      "matches": ["*://*/*"],
      "run_at": "document_start",
      "js": ["content-script.js"]
    }
  ],
  "permissions": [
    "scripting",
    "tabs",
    "notifications",
    "activeTab",
    "webRequest"
  ],
  "host_permissions": ["*://*/*", "https://*/*"],
  "web_accessible_resources": [
    {
      "matches": ["*://*/*", "http://*/*", "https://*/*"],
      "resources": ["web.js"]
    }
  ],
  "icons": {
    "32": "/icons/32x32.png"
  }
}

content-script.js

console.log("I am content script");
function injectScript() {
  var script = document.createElement("script");
  script.src = chrome.runtime.getURL("scripts/web.js");
  script.type = "text/javascript";
  console.log("Inserting Script", document);
  document.head.appendChild(script);
}
injectScript();

web.js

console.log("I am web.js");

setInterval(() => {
  console.log(window.test, "Test in setInterval");
}, 1000);

console.log(window.test, "Logging test from web.js");

// document.body.style.backgroundColor = "red";

Upon refreshing the page I am getting the following error enter image description here

Not able to get what could be the issue, can someone guide me? Thank You!

Rahul
  • 1,858
  • 1
  • 12
  • 33

0 Answers0