Firefox的扩展工程通过SDK,但没有安装在浏览器兼容性问题? [英] firefox extension works through sdk but not when installed in browser - compatibility issue?

查看:105
本文介绍了Firefox的扩展工程通过SDK,但没有安装在浏览器兼容性问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

---更新----

在进行了更多的实验之后,我确定我写的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:外部资源定位器,
图标: self.data.url(icon-16.png),
});

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




我想写一个简单的扩展为Firefox添加一个表单到当前页面,并将数据发布到另一个站点。它可以通过一个动作按钮或通过上下文菜单项调用。

我一直在使用附加sdk进行开发,并且在使用 cfx run 来测试它。但是,在执行 cfx xpi 并将扩展安装到我的Firefox浏览器中后,根本不起作用。操作按钮和上下文菜单项不会出现,虽然扩展名显示在附加组件扩展名下(如安装和启用),但没有任何与xpi打包在一起的图像会显示出来。



我不知道是什么原因导致的,我的代码很简短,所以我会添加我的整个main.js:

pre> 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:查找Babel库中的选定文本,
context:contextMenu.SelectionContext(),
contentScript:'self.on(click,function(){'+
'var text = window.getSelection()。toString();'+
'var formext = document.createElement( ';
'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.setAttrib ute(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:外部资源定位器,

图标: {
16:./icon-16.png,
32:./icon-32.png,
64:./icon- ()

onClick:function(){
require .js)
});
}
});

我注意到当我运行 cfx xpi 自动生成的install.rdf文件表示兼容性的最大版本是30.0。不过,我也发现,在一些运行Firefox的版本(包括38版本)的计算机上,它可以很好地工作。在这个代码中有什么会阻止与新版本的Firefox的兼容性?我将添加ContentScriptFile在可能是负责任的情况下:

$ p $ function getSelectedText(){
var text = ;
if(window.getSelection){
text = window.getSelection()。toString();
} else if(document.selection&& document.selection.type!=Control){
text = document.selection.createRange()。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); / /采取选定的文本或bodytext

formext.appendChild(hiddenField);
document.body.appendChild(formext);
formext.submit();


解决方案


  1. 打开上下文菜单选择 Customize ... 。在打开的窗口中,您可以在其他工具和功能中看到您的图标吗?如果是的话,这意味着Firefox在你开发插件的时候记得这个图标的缺失。您可以手动将图标放到工具栏上。
  2. install.rdf中手动更改 em:maxVersion

  3. 按照,至少是这些:



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


  4. 尝试备份并删除整个 firefox的个人资料文件夹,让Firefox百分百清洁。它有帮助吗?如果是的话,那么这个问题就会缩小到配置文件中。

  5. 尝试更改插件的所有标识符(包括插件名称,ID,描述,按钮ID和描述等)一个新的重复插件。这有帮助吗?如果是的话,那很可能意味着Firefox在你玩它的时候记得你的插件的一些设置。


---Update----

After experimenting more with this, I've determined that the contentScript I have written is not the problem here. For example, if I reduce the extension to merely:

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"),
  });

The button will still appear when I run the extension through the SDK, but will not appear when I install the xpi in a current firefox browser (version 38, on some platforms). This problem seems to be occurring at a very basic level in their design process.


I am trying to write a simple extension for firefox which appends a form to the current page and posts data to another site. It can be called by an action button or through a context menu item.

I have been developing with the add-on sdk and it is working perfectly when I use cfx run to test it. However, after doing cfx xpi and installing the extension into my firefox browser, it does not work at all. The action button and context menu item do not appear, and although the extension shows up under add-ons -> extensions as installed and enabled, none of the images packaged with the xpi will display.

I am not sure what could be causing this, and my code is fairly brief, so I will add my entire 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")
                               });
                              }
                              });

I've noticed that when I run cfx xpi the automatically generated install.rdf file says the maximum version for compatibility is 30.0. However, I have also found that on some computers running versions of firefox up to and including 38 it will work perfectly. Is there anything in this code which would prevent compatibility with newer versions of firefox? I will add the ContentScriptFile in case that may be responsible:

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. Open context menu on the toolbar where your icon would be, select Customize.... In the opened window, can you see your icon in "Additional tools and features"? If yes, then it means firefox remembered the icon's absence while you were developing the addon. You can put the icon to the toolbar manually. I believe regular users will not face this problem.
  2. Change your em:maxVersion manually in install.rdf
  3. Configure your firefox as described in Setting up an extension development environment, namely, at least these:

    • javascript.options.showInConsole = true to have addon errors shown in F12 console
    • javascript.options.strict = true to have even more warnings in the console
    • extensions.logging.enabled = true to have installation/update problems in the console.

    After that, restart firefox and see if you can get anything useful from console. Disable other addons to remove the noise.

  4. Try to backup and remove the entire firefox's profile folder, to have firefox 100% clean. Does it help? If yes, that narrow the problem to something in profile.
  5. Try to change all identifiers of your addon (including addon name, ID, description, button id and description, etc), thus making a new duplicate addon. Does that help? If yes, that most likely means firefox has remembered some settings for your addon while you played with it.

这篇关于Firefox的扩展工程通过SDK,但没有安装在浏览器兼容性问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆