开发Firefox扩展

简介:
1、 使用单独的profile文件作为开发环境
==================================================
Firefox 把用户的个人信息,包括设置、已安装的扩展等,都保存在一个概要文件中,默认是使用名为 default 的概要文件。通过创建一个专门为开发使用的概要文件,可以不影响正常的使用,也不会破坏个人信息。为了创建另外一个概要文件,运行 firefox -P,在弹出的“选择概要文件”的对话框中,新建一个名为 dev 的概要文件,并使用此概要文件来运行 Firefox。

注意:关闭所有正在运行的Firefox之后,再执行firefox -P。

即便是正在以normal为profile运行着firefox,也可以通过下面的命令启动以dev为profile的Firefox:
     firefox -no-remote -P dev



2. 安装如下扩展以便于开发
==================================================


3、设定preferences以便调试
======================================
type about:config in the Location Bar
下面一些设置默认时没有,需要自己创建,不过,如果先把上面2中提到的扩展先安装上,重启动Firefox后,这些设置是都有的:
  • options.showInConsole = true. Logs errors in chrome files to the Error Console.
  • nglayout.debug.disable_xul_cache = true. Disables the XUL cache so that changes to windows and dialogs do not require a restart. This assumes you're using directories rather than JARs. Changes to XUL overlays will still require reloading of the document overlaid.
  • browser.dom.window.dump.enabled = true. Enables the use of the dump() statement to print to the standard console. See window.dump for more info. You can also use nsIConsoleService from privileged ..
  • options.strict = true. Enables strict . warnings in the Error Console. Note that since many people have this setting turned off when developing, you will see lots of warnings for problems with their code in addition to warnings for your own extension. You can filter those with Console2.
  • extensions.logging.enabled = true. This will send more detailed information about installation and update problems to the Error Console.


4. 关于开发目录
==================================================
有两种设定开发目录的方法:

a、直接在C:\Documents and Settings\<您的登录用户名>\Application Data\Mozilla\Firefox\Profiles\???dev\extensions\[email]my_firefox_ext@gmail.com[/email]\下开发。

b、创建链接文件。
在C:\Documents and Settings\<您的登录用户名>\Application Data\Mozilla\Firefox\Profiles\???dev\extensions\下面创建一个文件名为[email]my_firefox_ext@gmail.com[/email]的文件。[email]my_firefox_ext@gmail.com[/email]中的内容为开发目录,比如:
d:\my_firefox_ext_dev\
这样firefox就能通过该文件找到d:\my_firefox_ext_dev\。注意[email]my_firefox_ext@gmail.com[/email]要和install.rdf中的
    <em:id>[email]my_firefox_ext@gmail.com[/email]</em:id>
保持一致!这个id要符合邮箱格式,或者符合GUID格式,应该是唯一的。


5、打包、发布和更新
==================================================
打包

扩展打包的过程非常简单。只需要把整个目录的内容打包成一个 ZIP 格式的文件,并把文件的扩展名改为 xpi 即可。需要注意的是 install.rdf 要在 ZIP 文件的根目录下面,这样扩展才能安装到 Firefox 中。

发布

如果您想让别人也来使用您开发的扩展,一种方式是直接把打包好的 xpi 文件发给对方,他只需要用 Firefox 打开这个文件,就会自动提示安装。另外一种方式是把该 xpi 文件存放在某个公开的 HTTP 服务器中,对方只需要用 Firefox 访问该 xpi 文件,就同样会自动提示安装。这里需要注意的是要正确的设置 xpi 文件的 MIME 类型。Firefox 能识别的 xpi 文件的 MIME 类型是 application/x-xpinstall。您可能需要配置您的 HTTP 服务器。

更新

如果您的扩展的开发周期较长,需要发布多个版本的话,可以利用扩展的自动更新的能力。这样当有新的版本发布时,Firefox 会自动提示用户去获取最新的版本。要实现自动更新,需要在扩展的 install.rdf 中指定描述更新信息的 rdf 文件的位置,该 rdf 文件通常命名为 update.rdf。在 update.rdf 中声明了当前最新的版本号和最新版本的下载地址。如果用户安装的扩展的版本低于 update.rdf 中声明的版本,则 Firefox 会提示用户是否更新。请参考本文附带的 源代码 中的 update.rdf 文件。 


6、安装多个版本的Firefox以便测试兼容性
参考[url]http://forums.mozillazine.org/viewtopic.php?t=613873[/url]


7、用下面命令可以把chrome作为独立程序运行
    firefox -chrome chrome://fireftp/content/fireftp.xul


8、参考:
==================================================

[url]https://developer.mozilla.org/en/Setting_up_extension_development_environment[/url]
[url]https://developer.mozilla.org/en/Setting_up_extension_development_environment[/url]
[url]https://developer.mozilla.org/en/Building_an_Extension[/url]
[url]http://www.ibm.com/developerworks/cn/web/wa-lo-firefox-ext/[/url]









本文转自 h2appy  51CTO博客,原文链接:http://blog.51cto.com/h2appy/128573,如需转载请自行联系原作者
目录
相关文章
|
Web App开发 Java Linux
LINUX开发FIREFOX的插件:编译npruntime
LINUX开发FIREFOX的插件:编译npruntime
118 0
|
Web App开发 JavaScript
Firefox 4.0 Beta 8开始开发 新引擎依然没影
Mozilla曾经说过,并且不止一次的说过,他们会在下一个Beta版中整合传说中非常强力的JaegerMonkey引擎,据说该引擎可以很好的解决Firefox在网页中Javascript脚本处理的低效率问题。
685 0
|
Web App开发 安全 数据安全/隐私保护