Firefox附加程序与“jpm run”一起工作,但是不能处理由“jpm xpi”生成的.xpi文件。 [英] Firefox add-on works with "jpm run", but not whith .xpi file generated with "jpm xpi"
问题描述
我使用 Firefox插件SDK
a>开发一个Firefox插件。我遵循入门指南
Firefox版本:41.0.2
我的程序是:
-
jpm run
- >确定加载项正常工作
-
jpm xpi
- > OK:创建 @ myAddon.xpi (JPM [info]成功创建 .xpi at ...) > - 使用 @ myAddon.xpi - > NOK
当我尝试在我的Firefox中安装插件(插件 - >从文件安装 - > @ myAddon.xpi ),我有一个消息安装成功。看起来不错。但是,附加功能不起作用。没有反应。
那么,为什么使用 jpm的测试运行
但是在安装 .xpi
文件后无法工作???
我可以与您分享代码,但这种情况怎么会发生?如果它在测试中工作,我期望它在发布中工作。
我没有收到任何错误或警告。
高级别:
Index.js :
$ p $
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;
请求({
url:param,
onComplete:function(response){
var parsed = JSON.parse(response.text);
worker .port.emit('got-request',parsed);
}
))。get();
}
$ b data / Compute.js
self.port.on('got-request',function(data){
console.log(data);
});
编辑(从评论中移除):
我找到一些有趣的东西....取决于FireFox的隐私级别,插件是否工作。(Options-> Pri - >历史记录记住历史记录或者不记历史记录 - 记住历史记录 - > addOn OK - 永远不要记录历史记录 - > addOn NOK任何想法为什么
正如你已经确定的,如果你希望你的Firefox附加SDK附加工作在隐私浏览模式您需要添加密钥隐私浏览
在 true rel =nofollow> package.json 档案。 ://developer.mozilla.org/en-US/Add-ons/SDK/Tools/package_json#Key_referencerel =nofollow>权限
$ b
permissions:{private-browsing:true}
关于编写用于私人浏览的SDK加载项的Firefox文档模式明确指出 <$如果以下任何一种情况发生,我们将会返回true(sdk / private-browsing)。isPrivate() 方法将会返回true。
中, >文件,您必须使用私人浏览模块
- 私人窗口,或者
- 属于私人窗口的标签
- 与隐藏在私人窗口中的文档关联的工作人员
- 任何窗口,选项卡或工作人员永远不会记住历史记录(选项 - >隐私 - >历史记录)
$ b没有
private-browsing:true
,那么就像文档状态,下面将会是这种情况(重点是我的):
- windows 模块将不会列出任何私人浏览器窗口,为私人浏览器窗口生成任何事件,或让附加组件打开任何私人浏览器窗口
- 标签模块将不会列出属于私人浏览器的任何标签窗口,并且该插件不会收到此类标签的任何事件。 ui 组件将不会在私人浏览器窗口中显示
使用上下文菜单将不会显示在属于私人浏览器窗口的上下文菜单中。 href =https://developer.mozilla.org/en-US/Add-ons/SDK/High-Level_APIs/page-mod =nofollow> page-mod 模块不会附加内容脚本到属于私人浏览器窗口的文档
- 任何
- 中的任何选择都不会包含org / en-US / Add-ons / SDK / High-Level_APIs / selectionrel =nofollow> selection 模块。 ul>
最终的效果是,如果您使用的配置文件配置为不记录历史记录,那么您的加载项似乎不起作用
private-browsing:true $如果你把这个权限放在你的 package.json
require(sdk / private-browsing)。isPrivate(object)
来检查是否在私人窗口或标签。如果你是在这样一个窗口或标签,你不需要存储任何关于这样的环境的信息。I'm using the Firefox Add-on SDK to develop a Firefox add-on. I have followed the Getting Started tutorial.
Firefox version : 41.0.2
My Process is :
jpm run
--> OK the add-on works finejpm xpi
--> OK : Create @myAddon.xpi (JPM [info] Successfully created .xpi at ...)- Use of @myAddon.xpi --> NOK
When I tried to install the add-on in my Firefox ( Add-on -> install from file -> @myAddon.xpi ), I have a message "Install successfully". Looks good. BUT, the add-on doesn't work. Nothing happens.
So, why is the test with jpm run
OK, but does not work after installing the .xpi
file???
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 :
Index.js:
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();
}
data/Compute.js
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. ( Options->Privacy->History "Remember history " or "Never remember history") - Remember history " --> addOn OK - "Never remember history" --> addOn NOK Any idea why
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.
If you are using no other permissions, you could add a line to your package.json file that looks like:
"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):
- 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):
- 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
- 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
- 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
- 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.
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. If you are in such a window or tab you need to not store any information about such environment.
这篇关于Firefox附加程序与“jpm run”一起工作,但是不能处理由“jpm xpi”生成的.xpi文件。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!