Firefox SDK:重定向到资源被拒绝 [英] Firefox SDK: Redirect to ressource HTML denied
问题描述
我正在尝试使用Addon SDK编写一个Firefox Addon,以根据URL重定向一些网站。我已经创建了一个HTML页面,并把它放在数据目录中。我得到的路径:
var data = require(sdk / self)。
var myWebsite = data.url(myWebsite.html);
我使用PageMod来给定一个URL数组来启动脚本:
$ p $
pageMod.PageMod({
include:ArrayOfUrls,
contentScriptFile:./myScript.js,
contentScriptOptions :{myWebsite:myWebsite}
});
在myScript.js中,我正在检查是否满足一些要求,如果是,我尝试重定向我的本地网站:
window.location.replace(self.options.myWebsite);
但是我总是在控制台中得到以下错误信息:
对象
- _errorType =错误
- message =从脚本被拒绝访问'resource://myAddon/data/myWebsite.html'
如果我手动输入本地网站的路径(resource:// myAddon / ...)它工作的浏览器的地址栏。如果我重定向到另一个网站(例如, http://example.com/ ),它也可以。
所以我想有一个安全设置,所以我需要改变,以使本地重定向可能,但我找不到任何文档或网络上。我希望这里有人可以告诉我我做错了什么。
在package.json中,我不得不添加以下行使其工作:
$ $ p $
permissions:{cross-domain-content:[resource:// myAddon / data /]}
更多文档可以在他的评论中提供的链接Noitidart中阅读。 >
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.
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.
这篇关于Firefox SDK:重定向到资源被拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!