0

I want to host my javascript file instead of packing it with the extension. I have read about whitelisting cross domain with Content Security Policy. This is what I have, but it throws error

"Could not load javascript '' for content script."

manifest.json

{
  "name": "My Chrome App",
  "version": "1.0",
  "manifest_version": 2,

  "content_scripts": [{
            "matches": ["<all_urls>"],
            "js": ["https://example.com/platform/myjs.js"],
            "run_at": "document_end"
  }],

  "background": {
        "scripts":["background.js"]
  },          

  "description": "My app description goes here", //on hover
  "icons": {
              "128": "icon.png"
  },

  "browser_action": {
              "default_title": "My Chrome App",
              "default_popup": "popup.html"
  },


  "permissions": [
              "http://*/*", "https://*/*","tabs"
  ],

  "content_security_policy": "script-src 'self' https://example.com; object-src 'self'"

}

Is it impossible what I am trying to do? Or is there a workaround? I cannot find an updated answer to this question since CSP has been updated a couple years ago.

UPDATE: As suggested by @PredatorIWD I looked at this answer but I am receiving the following error when I inspect views of background page:

Unchecked runtime.lastError while running tabs.executeScript: Cannot access a chrome:// URL

I was confused about why until I found this answer which solved my problem.

  • 3
    Possible duplicate of [Loading external javascript in google chrome extension](https://stackoverflow.com/questions/7781851/loading-external-javascript-in-google-chrome-extension). See the [second](https://stackoverflow.com/a/41442637/6586663) answer. – Luka Čelebić Apr 22 '18 at 22:26
  • I copied the code from that link into my background.js and changed the url to the js file, reinstalled the extension and it throws no errors but the downloaded javascript does not execute. – angieohangie Apr 23 '18 at 08:48
  • I found in the error in extension inspection: `Unchecked runtime.lastError while running tabs.executeScript: Cannot access a chrome:// URL` Do you know how do I fix using the supplied code? – angieohangie Apr 23 '18 at 11:25
  • By a simple google search of that error you already get [answers](https://stackoverflow.com/questions/24600495/chrome-tabs-executescript-cannot-access-a-chrome-url) as to why that is happening and how to fix it. – Luka Čelebić Apr 23 '18 at 17:10

0 Answers0