[英]Firefox add-on works with “jpm run”, but not whith .xpi file generated with “jpm xpi”
I'm using the Firefox Add-on SDK to develop a Firefox add-on. 我正在使用Firefox插件SDK开发Firefox插件。 I have followed the Getting Started tutorial .
我遵循了入门教程 。
Firefox version : 41.0.2 Firefox版本:41.0.2
My Process is : 我的过程是:
jpm run
--> OK the add-on works fine jpm run
>确定附加组件工作正常 jpm xpi
--> OK : Create @myAddon.xpi (JPM [info] Successfully created .xpi at ...) jpm xpi
xpi- >确定:创建@ myAddon.xpi (JPM [info]已在...成功创建.xpi ) So, why is the test with jpm run
OK, but does not work after installing the .xpi
file??? 因此,为什么使用
jpm run
的测试jpm run
正常jpm run
,但是在安装.xpi
文件后却无法正常工作???
I can share the code with you, but how can this situation happen? 我可以与您共享代码,但是这种情况怎么发生? If it works in test, I expect that it works in "release".
如果它可以在测试中工作,我希望它可以在“发行版”中工作。 I get no error or warning.
我没有错误或警告。
High Level : 高水平 :
pageMod.PageMod({
include: "*",
contentScriptFile: [data.url("jquery-1.11.3.min.js"), data.url("./Compute.js")],
onAttach: function (worker) {
var currentUrl = tabs.activeTab.url;
param = currentUrl;
Request({
url: param,
onComplete: function (response) {
var parsed = JSON.parse(response.text);
worker.port.emit('got-request', parsed);
}
}).get();
}
self.port.on('got-request', function (data) {
console.log(data);
});
Edit (moved from comments): 编辑(从评论中删除):
I find something interesting.... Depending on the level of privacy in FireFox the addon will work or not. 我发现一些有趣的事情。...取决于FireFox的隐私级别,该插件是否可以工作。 ( Options->Privacy->History "Remember history " or "Never remember history") - Remember history " --> addOn OK - "Never remember history" --> addOn NOK Any idea why
(选项->隐私->历史记录“记住历史记录”或“永远不要记住历史记录”)-记住历史记录--> addOn确定-“永远不要记住历史记录”-> addOn NOK任何想法
As you have determined, if you desire your Firefox Add-on SDK add-on to work in Private Browsing mode you need to have add the key private-browsing
with a value of true
in your package.json file. 如您所确定,如果您希望Firefox附加SDK附加组件在“ 私有浏览”模式下工作,则需要在package.json文件中添加值为
true
private-browsing
密钥。
If you are using no other permissions , you could add a line to your package.json file that looks like: 如果您没有使用其他权限 ,则可以在package.json文件中添加以下内容:
"permissions": {"private-browsing": true}
The Firefox documentation on writing SDK add-ons for private browsing mode specifically states that the require("sdk/private-browsing").isPrivate()
method will return true when any of the following is the case (emphasis mine): Firefox文档中有关为私人浏览模式编写SDK附加组件的文档特别指出,当以下任一情况出现时,
require("sdk/private-browsing").isPrivate()
方法将返回true(强调我的意思):
- a private window, or
私人窗户,或
- a tab belonging to a private window, or
属于私有窗口的标签,或者
- a worker that's associated with a document hosted in a private window
与私有窗口中托管的文档相关联的工作人员
- any window, tab, or worker if the browser has been configured to never remember history (Options->Privacy->History)
如果已将浏览器配置为从不记住历史记录,则为任何窗口,选项卡或工作程序(选项->隐私->历史记录)
If you do not have "private-browsing": true
, then, as the documentation states , the following will be the case (emphasis mine): 如果您没有
"private-browsing": true
,则如文档所述 ,将是以下情况(强调我的意思):
- the windows module will not list any private browser windows, generate any events for private browser windows, or let the add-on open any private browser windows
Windows模块不会列出任何专用浏览器窗口,不会为专用浏览器窗口生成任何事件,也不会让加载项打开任何专用浏览器窗口
- the tabs module will not list any tabs that belong to private browser windows, and the add-on won't receive any events for such tabs
选项卡模块不会列出属于私有浏览器窗口的任何选项卡,并且加载项不会收到此类选项卡的任何事件
- any ui components will not be displayed in private browser windows
任何ui组件都不会在专用浏览器窗口中显示
- any menus or menu items created using the context-menu will not be shown in context menus that belong to private browser windows
使用上下文菜单创建的任何菜单或菜单项都不会显示在属于专用浏览器窗口的上下文菜单中
- the page-mod module will not attach content scripts to documents belonging to private browser windows
page-mod模块不会将内容脚本附加到属于私有浏览器窗口的文档
- any panel objects will not be shown if the active window is a private browser window
如果活动窗口是专用浏览器窗口,则不会显示任何面板对象
- the selection module will not include any selections made in private browser windows
选择模块将不包括在私有浏览器窗口中进行的任何选择
The net effect will be that your add-on will appear to not work when the profile you are using is configured to never remember history without having the "private-browsing": true
permission in your package.json . 最终的结果是,当您正在使用的配置文件配置为在package.json中没有
"private-browsing": true
权限的情况下永远无法记住历史记录时,您的加载项将无法正常工作。
If you do put that permission in your package.json file, you must use the private-browsing module, require("sdk/private-browsing").isPrivate(object)
, to check for being in a private window or tab. 如果确实将该权限放入package.json文件,则必须使用私有浏览模块
require("sdk/private-browsing").isPrivate(object)
来检查是否位于私有窗口或选项卡中。 If you are in such a window or tab you need to not store any information about such environment. 如果您在这样的窗口或选项卡中,则无需存储有关此类环境的任何信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.