我的附加程序是从使用GM_函数的Greasemonkey脚本编译而成的,在Firefox 31+版本中无法正常工作

幸运的

我有一个Firefox插件,它是一个基于覆盖的扩展程序,可在Firefox 31以下版本中使用。但是在32或更高版本中不起作用。我通常使用Userscript编译器工具来构建扩展程序。我的扩展程序在控制台中看不到任何东西(错误/输出)。

虽然当我使用Greasemonkey插件运行脚本时,它的工作正常。问题是在将扩展程序构建为XPI文件后运行扩展程序时。

下面是我的扩展结构:

myextension
 |-->skin
    |-->classic
 |-->content
    |-->myscript.user.js
    |-->myscriptPrefman.js
    |-->myscriptScript-compiler.js
    |-->myscriptXmlhttprequester.js
    |-->script-compiler-overlay.xul
 |-->chrome
 |-->install.rdf
 |-->icon.png
 |-->chrome.manifest

以下是install.rdf文件内容:

<?xml version="1.0"?>
<RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:em="http://www.mozilla.org/2004/em-rdf#">
<Description about="urn:mozilla:install-manifest">
<em:id>{9ef9b86c-03da-4e10-9552-e97a6d258af5}</em:id>
<em:name>Sample Extension</em:name>
<em:version>2.6</em:version>
<em:description>A sample extension - Firefox</em:description>
<em:creator>Mozdev</em:creator>
<em:contributor>Greasemonkey Compiler by Anthony Lieuallen;</em:contributor>
<em:contributor>http://arantius.com/</em:contributor>
<em:homepageURL>www.example.com</em:homepageURL>
<em:targetApplication><Description>
<em:id>{ec8030f7-c20a-464f-9b0e-13a3a9e97384}</em:id>
<em:minVersion>2.0</em:minVersion>
<em:maxVersion>35.*</em:maxVersion>
</Description>
</em:targetApplication>
</Description>
</RDF>

chrome.manifest 内容:

content myextension content/
overlay chrome://browser/content/browser.xul   chrome://myextension/content/script-compiler-overlay.xul
skin myextension classic/1.0 skin/classic/

我是否需要更改扩展名中的任何内容或将其转换为Bootstrap扩展名或使用附加SDK来构建XPI文件?

更新:

我遵循了Wladimir建议的Add-on SDK方法,并创建了XPI安装程序文件。但是用户脚本未在页面内运行。
该代码仍从Greasemonkey附加组件运行。

这是Greasemonkey脚本,可以在Greasemonkey中正常运行,但是当既不通过编译器也不通过SDK进行扩展时,则不能。

我按照以下步骤在本地计算机上安装了附加SDK。我使用cfx命令来构建XPI文件。我将其安装在Firefox最新版本(版本33.0.2)中,并访问openuserjs.org我什么都看不到。这是为什么?

幸运的

我仅通过将Firefox Request Api用于GM_XmlhttpRequest和用于在本地存储信息的本地存储来复制了代码。并使用Message Passing使脚本与main.js通信,Message Passing是Restartless Firefox Addon SDK Api的基础。

var data = require("self").data;
var pageMod = require("page-mod");
pageMod.PageMod({
  include: "*.example.com", //mywebsite url
  contentScriptWhen: 'start',
  contentScriptFile: data.url("contentScript.js")
});

contentScriptFile是您要编写用户脚本并使用最新的Firefox AddonSDK API中的端口消息传递与main.js进行通信的地方。

我使用Request API从服务器获取信息,而不是使用不受支持的GM_xmlhttpRequest。

var Request = require("sdk/request").Request;
var userDetails = Request({
  url: "http://example.com/user/1",
  onComplete: function (response) {
    var res = response.json[0];
  }
});

现在,该扩展不再需要重新启动,并且可以使用Firefox文档中的高级和低级api对其进行完全重写。希望将来的浏览器更改将使用这些api并在更长的时间内支持扩展。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

Related 相关文章

热门标签

归档