2

I'm trying to load the JS from an external server, so that my extension can be updated and developed without needing to update the chrome extension. This is my current manifest:

{
  "name": "Test",
  "version": "1.0",
  "manifest_version": 2,
  "description": "Test extension",  
  "content_security_policy": "script-src 'self' https://test.dev77.net/; object-src 'self'",
  "content_scripts": [
    {
      "matches": ["http://google.com"],
      "js": ["https://test.dev77.net/test.js"]
    }
  ]
}

I get the following when attempting to install the extension:

Could not load javascript 'https://test.dev77.net/test.js' for content script.

Joren
  • 9,623
  • 19
  • 63
  • 104
  • Related / possible duplicate: [Chrome extension adding external javascript to current page's html](http://stackoverflow.com/questions/10285886/chrome-extension-adding-external-javascript-to-current-pages-html/10371025#10371025) (the question is worded differently, but the answer is fully applicable to your question). – Rob W Sep 28 '12 at 12:50

1 Answers1

3

First of all, I advice you to don't do it this way. Its better to upload your extension to Chrome Web Store every time. You can do your extension autoupdateable, so the users will have allways the last version.

Said that, you know extensions doesn't support external js. There's a security reason. For example, Chrome Web Store scans the uploaded extensions searching for malware. They couln't do it if the js changes.

But, there's a workaround. Your extension code could load the js using Ajax, and then "eval" it.

Another way is to insert a script tag in the user page, to load a js file. Then you execute it (it's tricky, because of the isolated world thing, but Google explains how to do it nevertheless in its Chrome Extensions page).

Alejandro Silvestri
  • 3,706
  • 31
  • 43
  • Would either of those methods still allow you to use the cross site scripting support you get with chrome extensions? – Joren Oct 01 '12 at 23:26