5

I've been trying to move a simple program I made in jQuery/HTML to a Firefox WebExtension for easy deployment. The error I am getting is:

Content Security Policy: The page’s settings blocked the loading of a resource at https://code.jquery.com/jquery-1.12.4.js (“script-src moz-extension://ef8f1295-1912-4912-ab2e-121053b6781a”).

I'm sure I'm just not doing the manifest.json file right, but for the life of me I don't know where:

{
  "description": "Makes tasks from different underwriters uniform",
  "manifest_version": 2,
  "name": "Task Creator",
  "version": ".5",
  "permissions": [
    "http://*/*", "tabs", "https://*/*"
  ],

  "icons": {
    "48": "icons/page-48.png"
  },
  "web_accessible_resources": [
    "style/popUpStyle.css",
    "script/popUpTask.js",
    "script/logicTaskFiller.js",
    "js/autosize.js",
    "style/https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css",
    "js/https://code.jquery.com/jquery-1.12.4.js",
    "js/https://code.jquery.com/ui/1.12.1/jquery-ui.js"
  ],

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

  "browser_action": {
    "default_icon": "icons/page-32.png"
  }
}
Makyen
  • 31,849
  • 12
  • 86
  • 121
Branden Ham
  • 92
  • 1
  • 1
  • 7

1 Answers1

5

By default, extensions cannot load scripts, or other object resources, from the Internet. All CSS and JavaScript content used by your extension should be part of the extension package.

(This documentation is from Chrome, but the exact same policies apply to Firefox WebExtensions.)

It's possible to relax these restrictions somewhat, but this should generally be avoided -- loading resources from a remote server will make your extension fail to work properly if the user does not have Internet access, or if they are behind a restrictive firewall. Additionally, addons.mozilla.org will not accept addons which execute remotely hosted Javascript.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
  • As stated, this is wrong, as you _can_ relax the policy. – Xan Oct 21 '16 at 21:06
  • 2
    @Xan, While you may be able to technically relax the policy, if you intend to have a WebExtension hosted by [AMO](https://addons.mozilla.org/en-US/firefox/) (the "normal" distribution method for Firefox Extensions), any JavaScript you use should be included with the extension package. Any such common libraries should exactly match copies available for download. That they do match will be checked during the review process. If you load JavaScript from an external resource, you are unlikely to pass a review for hosting on AMO. – Makyen Oct 21 '16 at 21:22
  • 1
    I don't disagree. But the original statement was still incorrect, and now corrected. – Xan Oct 21 '16 at 21:23
  • @Makyen That's also a good point! I've added a note about that. –  Oct 21 '16 at 21:26