1

I'm trying to write a Firefox Addon with the Addon SDK to redirect some websites based on their URL. I have created a HTML page and put it in the data directory. I get the path with:

var data = require("sdk/self").data;
var myWebsite = data.url("myWebsite.html");

I'm using PageMod to start a script given an array of URLs:

pageMod.PageMod({
    include: ArrayOfUrls,
    contentScriptFile: "./myScript.js",
    contentScriptOptions: {"myWebsite" : myWebsite}
});

In myScript.js I'm checking if some requirements are fulfilled and if so I try to redirect to my local website with:

window.location.replace(self.options.myWebsite);

But I always get the following error message in the console:

Object
- _errorType = Error
- message = Access to 'resource://myAddon/data/myWebsite.html' from script denied

If I enter the path to the local website (resource://myAddon/...) manually in the adress bar of the browser it works. If I redirect to another website (e.g. http://example.com/) it works as well.

So I guess there's a security setting or so I need to change to make the local redirect possible, but I can't find anything in the documentation or on the web. I hope somebody here can tell me what I'm doing wrong.

Noitidart
  • 35,443
  • 37
  • 154
  • 323
  • Yeah you're running this from a contentScript. That's non-privelaged code trying to access priveledaged URI. `resource://` and `chrome://` are privelaged URI's. That's interesting though I thought resource wouldn't have this issue. So maybe its a cross domain issue (as reousrce domain is diffrent from the websites you are running the contentscript form)? Try setting this cross domain thing: https://developer.mozilla.org/en-US/Add-ons/SDK/Guides/Content_Scripts/Cross_Domain_Content_Scripts – Noitidart Sep 17 '15 at 11:53
  • 1
    Thanks, that solved it. For future references I've added the following line in package.json: `"permissions": {"cross-domain-content": ["resource://myAddon/data/"]}` –  Sep 17 '15 at 12:47
  • Super! Can you please post that as solution and accept it. – Noitidart Sep 17 '15 at 12:49

1 Answers1

2

In package.json I had to add the following line to make it work:

"permissions": {"cross-domain-content": ["resource://myAddon/data/"]}

Further documentation can be read in link Noitidart provided in his comment.