firefox 扩展通过 sdk 工作,但在浏览器中安装时不工作 - 兼容性问题?

firefox extension works through sdk but not when installed in browser - compatibility issue?

---更新----

在对此进行更多试验后,我确定我编写的 contentScript 不是这里的问题。例如,如果我将扩展名缩减为:

var buttons = require('sdk/ui/button/action');
var data = require("sdk/self").data;
var self = require("sdk/self");


var button = buttons.ActionButton({
id: "library-link",
label: "External Resource Locator",
icon: self.data.url("icon-16.png"),
  });

当我通过 SDK 运行 扩展时,该按钮仍然会出现,但当我在当前的 firefox 浏览器(版本 38,在某些平台上)中安装 xpi 时,该按钮不会出现。这个问题似乎在他们的设计过程中发生在一个非常基本的层面。


我正在尝试为 firefox 编写一个简单的扩展,它将表单附加到当前页面并将数据发布到另一个站点。它可以通过操作按钮或上下文菜单项调用。

我一直在使用附加 sdk 进行开发,当我使用 cfx run 对其进行测试时它运行良好。但是,在执行 cfx xpi 并将扩展安装到我的 firefox 浏览器之后,它根本不起作用。操作按钮和上下文菜单项不会出现,虽然扩展显示在加载项下 -> 已安装和启用的扩展,但将显示与 xpi 打包的图像的 none。

我不确定是什么原因造成的,而且我的代码相当简短,所以我将添加我的整个 main.js:

var buttons = require('sdk/ui/button/action');
var data = require("sdk/self").data;
var contextMenu = require("sdk/context-menu");
var self = require("sdk/self");

var menuItem = contextMenu.Item({
                            label: "Look for selected text in the Library of Babel",
                            context: contextMenu.SelectionContext(),
                             contentScript: 'self.on("click", function () {' +
                            'var text = window.getSelection().toString();' +
                            'var formext = document.createElement("form");' +
                            'formext.setAttribute("method", "POST");' +
                            'formext.setAttribute("action", "https://libraryofbabel.info/resourcelocator.cgi");' +
                            'var hiddenField = document.createElement("input");' +
                            ' hiddenField.setAttribute("type", "hidden");' +
                             'hiddenField.setAttribute("name", "extension");' +
                            ' hiddenField.setAttribute("value", window.getSelection().toString());' +
                            ' formext.appendChild(hiddenField);' +
                            ' document.body.appendChild(formext);' +
                            ' formext.submit();' +
                            '});',
                            image: self.data.url("icon-16.png")
                            });

var button = buttons.ActionButton({
id: "library-link",
label: "External Resource Locator",

icon: {
"16": "./icon-16.png",
"32": "./icon-32.png",
"64": "./icon-64.png"
},
onClick: function() {
 require("sdk/tabs").activeTab.attach({
                              contentScriptFile: data.url("form.js")
                               });
                              }
                              });

我注意到当我 运行 cfx xpi 时,自动生成的 install.rdf 文件显示兼容性的最高版本是 30.0.但是,我还发现在某些计算机上 运行ning 版本的 firefox 高达并包括 38,它可以完美地工作。此代码中是否有任何内容会阻止与较新版本的 firefox 兼容?我将添加 ContentScriptFile 以防万一:

function getSelectedText() {
var text = "";
if (window.getSelection) {
    text = window.getSelection().toString();
} else if (document.selection && document.selection.type != "Control") {
    text = document.selection.createRange().text;
}
return text;
}

var bodytext = document.getElementsByTagName("BODY")[0];
var formext = document.createElement("form");
formext.setAttribute("method", "POST");
formext.setAttribute("action", "https://libraryofbabel.info/resourcelocator.cgi");
//formext.setAttribute("target","_blank");

var hiddenField = document.createElement("input");
hiddenField.setAttribute("type", "hidden");
hiddenField.setAttribute("name", "extension");
hiddenField.setAttribute("value", getSelectedText() || document.body.innerHTML); // take selected text OR bodytext

formext.appendChild(hiddenField);
document.body.appendChild(formext);
formext.submit();
  1. 在您的图标所在的工具栏上打开上下文菜单,select Customize...。在打开的window中,你能在"Additional tools and features"中看到你的图标吗?如果是,则意味着 firefox 在您开发插件时记住了该图标的缺失。您可以手动将图标放到工具栏上。相信普通用户不会遇到这个问题。
  2. install.rdf
  3. 中手动更改 em:maxVersion
  4. 按照 Setting up an extension development environment 中的描述配置您的 firefox,即至少这些:

    • javascript.options.showInConsole = true 在 F12 控制台中显示插件错误
    • javascript.options.strict = true 在控制台中显示更多警告
    • extensions.logging.enabled = true 控制台出现 installation/update 问题。

    之后,重新启动 firefox 并查看是否可以从控制台获得有用的信息。禁用其他插件以消除噪音。

  5. 尝试备份并删除整个 firefox's profile folder,让 Firefox 100% 干净。有帮助吗?如果是,则将问题缩小到配置文件中的某些内容。
  6. 尝试更改插件的所有标识符(包括插件名称、ID、描述、按钮ID和描述等),从而制作一个新的重复插件。这有帮助吗?如果是,那很可能意味着 firefox 在您使用它时记住了您的插件的一些设置。