在Firefox扩展中导入Javascript模块

oyenamit

我正在开发一个简单的Firefox扩展程序,但是无法导入我的自定义Javascript模块文件。bootstrap.js文件位于根目录下,test.jsm并且位于content文件夹内。test.jsm导出2个符号,foobar作为:

this.EXPORTED_SYMBOLS = ["foo", "bar"];

根据使用JavaScript代码模块文章,我已经contentchrome.manifest文件中有一条说明

content     myaddon   content/

所以,我应该能够导入test.jsmbootstrap.js如下:

 Components.utils.import("chrome://myaddon/content/test.jsm");

但是我在浏览器控制台中看到以下2条警告:

addons.xpi
WARN
Error loading bootstrap.js for [email protected]: [Exception... "Component returned failure code: 0x80520012 (NS_ERROR_FILE_NOT_FOUND) [nsIXPCComponents_Utils.import]"
nsresult: "0x80520012 (NS_ERROR_FILE_NOT_FOUND)"
location: "JS frame :: resource://gre/modules/addons/XPIProvider.jsm ->
jar:file:///Users/oyenamit/Library/Application%20Support/Firefox/Profiles/profilename/extensions/[email protected]!/bootstrap.js :: <TOP_LEVEL> :: line 1"
data: no] Stack trace: resource://gre/modules/addons/XPIProvider.jsm ->
jar:file:///Users/oyenamit/Library/Application%20Support/Firefox/Profiles/profilename/extensions/[email protected]!/bootstrap.js:1
< resource://gre/modules/addons/XPIProvider.jsm:4348
< XPI_loadBootstrapScope()@resource://gre/modules/addons/XPIProvider.jsm:4348
< XPI_callBootstrapMethod()@resource://gre/modules/addons/XPIProvider.jsm:4423
< AI_startInstall/<()@resource://gre/modules/addons/XPIProvider.jsm:5849
< next()@self-hosted:675 < TaskImpl_run()@resource://gre/modules/Task.jsm:330
< Handler.prototype.process()@resource://gre/modules/Promise.jsm ->
resource://gre/modules/Promise-backend.js:867 <
this.PromiseWalker.walkerLoop()@resource://gre/modules/Promise.jsm ->
resource://gre/modules/Promise-backend.js:746 <
this.PromiseWalker.scheduleWalkerLoop/<()@resource://gre/modules/Promise.jsm ->
resource://gre/modules/Promise-backend.js:688 < <file:unknown>




addons.xpi
WARN
Exception running bootstrap method startup on [email protected]: ReferenceError: foo is not defined (resource://gre/modules/addons/XPIProvider.jsm ->
jar:file:///Users/oyenamit/Library/Application%20Support/Firefox/Profiles/profilename/extensions/[email protected]!/bootstrap.js:16:4) JS Stack trace:
[email protected]://gre/modules/addons/XPIProvider.jsm ->
jar:file:///Users/oyenamit/Library/Application%20Support/Firefox/Profiles/profilename/extensions/[email protected]:16:5 <
[email protected]:4451:9 <
AI_startInstall/<@XPIProvider.jsm:5864:13

我究竟做错了什么?我正在使用Firefox 39.0。

可以从此处下载示例XPI文件

诺蒂达特

自定义JSM模块需要导入startupbootstrap.js文件功能中,我不知道为什么这样做,但是它只是那样工作。如果将其导入文件顶部,它将无法正常工作。

请确保在关机时将其卸载,这是一个非常简单的演示,并提供了有关如何进行操作的指南:

https://gist.github.com/Noitidart/9045387#file-bootstrap-js-L6

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

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

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章