简体   繁体   English

Firefox加载项可与“ jpm run”一起使用,但不能与“ jpm xpi”生成的.xpi文件一起使用

[英]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 : 我的过程是:

  1. jpm run --> OK the add-on works fine jpm run >确定附加组件工作正常
  2. jpm xpi --> OK : Create @myAddon.xpi (JPM [info] Successfully created .xpi at ...) jpm xpi xpi- >确定:创建@ myAddon.xpi (JPM [info]已在...成功创建.xpi
  3. Use of @myAddon.xpi --> NOK 使用@ 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". 当我尝试在Firefox中安装插件(插件->从文件安装-> @ myAddon.xpi )时,出现消息“安装成功”。 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??? 因此,为什么使用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 : 高水平 :

Index.js : 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 数据/ 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. 我发现一些有趣的事情。...取决于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.

相关问题 Object.defineProperty()在测试(运行jpm)期间工作,但是在使用实际的xpi时却不执行任何操作 - Object.defineProperty() works during testing (jpm run), but doesn't do anything when using the actual xpi Firefox附加组件:cfx run运行良好,cfx xpi可以工作,但附加组件什么都不做 - Firefox add-ons: cfx run works great, cfx xpi works but the add-on does nothing 尝试在 Firefox 中安装我的附加组件的 .xpi 文件时,附加组件“似乎已损坏” - Add-on "appears to be corrupt" when trying to install my add-on's .xpi file in Firefox 每次我改变我正在开发的Firefox插件时,我是否必须使用`jpm run`? - Do I have to use `jpm run` every time I change the Firefox add-on I'm developing? 将 `jpm run` 用于 Firefox Add-on SDK 扩展时,如何将数据持久存储在 `localStorage` 中 - How to persistently store data in `localStorage` when using `jpm run` for a Firefox Add-on SDK extension 使用jpm run测试Firefox附加SDK扩展时如何启用调试 - How to enable debuging when using jpm run to test a Firefox Add-on SDK extension 如何使用jpm将index.js以外的文件添加到Firefox加载项 - How to add a file other than index.js to a Firefox add-on using jpm 使用Mozilla API签署Firefox附加组件并下载已签署的XPI - Signing a firefox add-on with Mozilla api and download signed xpi 修改Firefox附加SDK扩展名的.xpi以在扩展名启动时运行命令 - Modify .xpi of Firefox Add-on SDK extension to run a command on extension startup 将Firefox附件导出/打包到Web扩展xpi - Exporting/Packaging Firefox add-on to web extension xpi
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM