简体   繁体   中英

chrome extension execute script not working with content_script

Aim is to inject a content script into a eventpage script in google chrome extension with no popup menu when button is clicked. Current error message is

tabs.executeScript: Cannot access a chrome:// URL

In the content_script a fetch request is made, if you have any tips on that as well it would be greatly appreciated.

Event Page Content Script

chrome.browserAction.onClicked.addListener(function (tab) {
  chrome.tabs.executeScript(null, {file: "content_script.js"});
});

Manifest

{
  "manifest_version": 2,

  "name": "Seneca One add Bookmark",
  "description": "Posts URL to database.",
  "version": "2.0",
  "background": {
    "scripts": ["eventPage.js"],
    "persistent": false
  },
  "browser_action": {
    "default_icon": "Favicon@2x.png",
    "default_title": "Add bookmark"
  },
  "content_scripts": [
  {
    "matches": ["http://*/*"],
    "js": ["content_script.js"]
  }
],
  "permissions": [
    "activeTab",
    "storage",
    "tabs",
    "http://*/*",
    "https://*/*"
  ]
}

@woxxom is correct when he says you are opening a script on a chrome extension. Make a popup.html with the browser action and then just make it run and then close itself instantly. Make sure your popup.js is in the default_script : popup.js in your manifest. Then you could make background { persistent : true } in your manifest to make your script working the background on every page and listening for your fetch. So essentially the same effect of what you are looking for. You click the icon your popup.html/popup.js runs the fetch / instantly disappears, while your background js is running in the background answering.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM