编辑现有的 Firefox 插件
对于我正在从事的项目之一,我必须使用 DOM Inspector 来调试 Firefox 扩展。
DOM 检查器的问题在于,它只向您显示代码下方的浏览器,无法分离浏览器或并排显示代码部分或浏览器。
它对我不起作用,因为我正在调试的插件有一个很大的 xul 覆盖层,并且有问题的区域位于底部,因此没有物理方法可以查看该区域的代码以及该区域本身。
所以我决定修改 DOM Inspector 本身,将浏览器放置在代码编辑器的一侧。
以下是我执行的步骤:
- 从配置文件目录中获取现有的 xpi 文件。
- 改成zip了。
- 进入内部并使用
jar -xf
提取inspector.jar
- 进入
inspectorOverlay.xul
并更改
是一个 hbox。 (这应该足以水平定位这两个窗口。) - 然后我使用
jar cf
重新创建了 jar 文件。 - 压缩目录,确保名称相同,并将扩展名更改回 xpi。
但是,当我尝试运行它时,我收到以下警告:
Warning: WARN addons.xpi: Add-on is invalid: [Exception... "Component returned failure code: 0x80520006 (NS_ERROR_FILE_TARGET_DOES_NOT_EXIST) [nsIZipReader.getInputStream]" nsresult: "0x80520006 (NS_ERROR_FILE_TARGET_DOES_NOT_EXIST)" location: "JS frame :: resource://gre/modules/XPIProvider.jsm :: loadManifestFromZipReader :: line 740" data: no]
Source File: resource://gre/modules/XPIProvider.jsm
Line: 740
Warning: WARN addons.xpi: Could not uninstall invalid item from locked install location
Source File: resource://gre/modules/XPIProvider.jsm
Line: 2042
我的问题是 - 通常我还需要进行哪些其他更改才能正确解释 xpi?
For one of the projects I'm working on, I have to use DOM Inspector to debug a Firefox extension.
The problem with DOM inspector is that it only shows you the browser below the code, there's no way to detach the browser or out the code section or browser side by side.
It didn't work for me because the plugin I was debugging had a large xul overlay, and the problematic area was at the botton, so there's no physical way to see the code for the area as well as the area itself.
So I have decided to modify DOM Inspector itself to place browser to the side of the code editor.
Here are the steps I undertook:
- Took the existing xpi file from the profile directory.
- Changed it to be a zip.
- Went inside and extracted
inspector.jar
usingjar -xf <filename>
- Went to
inspectorOverlay.xul
and changed<vbox id="bxInspectorMain">
to be an hbox. (This should be enough to position those two windows horizontally.) - Then I recreated jar file using
jar cf
. - Zipped the directory making sure that the name is the same and changed extension back to xpi.
However, when I try to run it, I get the following warnings:
Warning: WARN addons.xpi: Add-on is invalid: [Exception... "Component returned failure code: 0x80520006 (NS_ERROR_FILE_TARGET_DOES_NOT_EXIST) [nsIZipReader.getInputStream]" nsresult: "0x80520006 (NS_ERROR_FILE_TARGET_DOES_NOT_EXIST)" location: "JS frame :: resource://gre/modules/XPIProvider.jsm :: loadManifestFromZipReader :: line 740" data: no]
Source File: resource://gre/modules/XPIProvider.jsm
Line: 740
Warning: WARN addons.xpi: Could not uninstall invalid item from locked install location
Source File: resource://gre/modules/XPIProvider.jsm
Line: 2042
My question is - what other changes do I generally need to make for the xpi to be properly interpreted?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
@Luka,我想弗拉基米尔·帕兰特是正确的。为了避免修改现有项目的源代码时出现错误,我建议您在工作环境中工作。
编辑源代码的建议方法:
这样您就可以避免任何类型的错误,因为所有内容都会自动分类(Chrome 文件夹、清单、install.rdf、did dies 等)。
注意:有一种修改源代码的高级方法,FF 浏览器将通过在 FF 扩展配置文件文件夹中设置环境来自动检测源代码的修改。
@Luka, I guess Wladimir Palant is correct. To avoid error during the modification of source code of the existing project, I would suggest you to work in the working environment.
The suggested way to edit your source code:
This way you can avoid any kind of errors because everything will be classified automatically (Chrome folder, manifest, install.rdf, did dies etc).
Note: There is an advanced way of modifying source code and FF browser wil detect the modification of your source code automatically by setting the environment in your FF extension profile folder.
我猜你在这一步做错了什么。查看源代码,消息来自方法
updateMetadata()
- Firefox 注意到文件已更改并尝试再次读取install.rdf
。该文件应该位于 XPI 文件的顶层,但在您的情况下找不到它。重新打包文件后,也许install.rdf
不再位于顶层。您可以使用unzip
命令对其进行测试:它应该显示 XPI 文件的内容,包括
install.rdf
和chrome.manifest
- 无需任何前置目录名称。I guess that you did something wrong in this step. Looking at the source code, the message comes from method
updateMetadata()
- Firefox noticed that the file changed and tries to read ininstall.rdf
again. That file should be at the top level of the XPI file but in your case it cannot be found. Maybeinstall.rdf
is no longer at the top level after you repacked the file. You can test it with theunzip
command:It should show the contents of the XPI file, including
install.rdf
andchrome.manifest
- without any prepended directory name.