登录

如何编写Firefox扩展(2)-配置开发环境

July 9th, 2008

想要快速方便的开发Firefox扩展,配置一下开发环境,做些必要的准备是必须的。

设置Firefox配置

为了避免开发中的扩展平时使用的Firefox的性能,我们需要重新创建一个配置,并且将其命名为"dev",然后用以下的命令行来启动这个配置为开发环境的Firefox

start "" "%ProgramFiles%\Mozilla Firefox\firefox.exe" -no-remote -P dev

想要运行默认的配置,使用 "firefox" 或 "firefox -P default".

您还可以同时运行稳定版和开发中的Firefox版本,来检查扩展的兼容性y (Installing Firefox 3 or Minefield while keeping Firefox 2).

开发环境配置

下面的这些配置可以使开发调试扩展更加方便。查看  Editing Configuration Files 了解更多信息。 下面的这些选项,默认是不会在about:config中列出来的,所以需要手工添加它们。方法是,在你的firefox的配置目录下找到user.js ,如果文件不存在,就手工创建一个,然后添加以下几行

user_pref("nglayout.debug.disable_xul_cache",true);
user_pref("browser.dom.window.dump.enabled",true);

提示:firefox3.0中user.js已经被prefs.js代替了

下面是一些可用的配置选项、

  • javascript.options.showInConsole = true. 记录错误日志到 Error Console.
  • nglayout.debug.disable_xul_cache = true. 禁止XUL缓存,这样当修改界面元素时,就不需要重新启动firefox了。此选项只有当你使用了目录而不是jar的格式安装扩展时有效,并且修改XUL的行为时仍然需要重新启动。
  • browser.dom.window.dump.enabled = true. 允许使用dump() 命令输出信息到标准控制台 See window.dump for more info. You can also use nsIConsoleService from privileged script.
  • javascript.options.strict = true.  Enables strict JavaScript 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.

用来辅助进行Firefox扩展开发的一些Firefox扩展

名字有点拗口,但绝对都是好东西

自定义代码位置

为了使每次修改代码后,不需要重复的进行扩展的安装,你可以将你的源码放到Firefox的配置目录下,Firefox会自动检测并加载你的扩展

  1. 在 install.rdf 中找到扩展编号,如 em:id="{46D1B3C0-DB7A-4b1a-863A-6EE6F77ECB58}"
  2. 在your_profile_directory/extensions/ 目录下创建一个目录,目录名为刚刚找到的编号(eg. `your_profile_directory/extensions/{46D1B3C0-DB7A-4b1a-863A-6EE6F77ECB58}`) (Find your profile directory)
  3. 将你的开发文件,复制到这个目录下
  4. 重新启动Firefox.


我要留言

麻烦,计算一下:7+4= 我不想算,点击这里登录/留言



订阅

google reader 抓虾
bloglines my yahoo
哪吒 鲜果
* 更多订阅本站方式请看 订阅帮助