Firefox SDK: Redirect to ressource HTML denied

不羁的心 提交于 2019-12-24 16:42:46

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/32626462/firefox-sdk-redirect-to-ressource-html-denied

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!