本文介绍了Firefox附加程序与“jpm run”一起工作,但是不能处理由“jpm xpi”生成的.xpi文件。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用您需要添加密钥隐私浏览在档案。 ://developer.mozilla.org/en-US/Add-ons/SDK/Tools/package_json#Key_referencerel =nofollow>权限,你可以添加一行到你的 package.json
$ b

 permissions:{private-browsing:true} 

模式明确指出方法将会返回true。

最终的效果是,如果您使用的配置文件配置为不记录历史记录,那么您的加载项似乎不起作用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 :

  1. jpm run --> OK the add-on works fine
  2. jpm xpi --> OK : Create @myAddon.xpi (JPM [info] Successfully created .xpi at ...)
  3. 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):

If you do not have "private-browsing": true, then, as the documentation states, the following will be the case (emphasis mine):

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文件。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 20:49