繁体   English   中英

firefox附加组件包括timbre.js

[英]firefox add-on include timbre.js

我试图对firefox进行扩展,因此我需要使用timbre.js( http://mohayonao.github.io/timbre.js/ ),因此我想将其包含在contentScriptFile中并在测试中使用它。 js文件是这样的:

exports.main = function() {
    var widget = new Widget({
        id: "widget",
        label: "Label",
        contentURL: "cat.png",
        contentScriptFile: [data.url('timbre.js'), data.url('test.js')]      
    });

问题是由于以下原因它不会加载:

时间戳:16. 07. 13 12:35:33错误:addon_name:发生异常。 NS_ERROR_FAILURE:故障回溯(最近一次调用最近):文件“ resource://gre/modules/commonjs/sdk/content/symbiont.js”,第172行,位于_onReady self._onInit();中。 文件“ resource://gre/modules/commonjs/sdk/widget.js”,第803行,为null this._initSymbiont(); 在Symbiont <._ onInit this._initWorker({window:this._frame.contentWindow})中的文件“ resource://gre/modules/commonjs/sdk/content/symbiont.js”,第200行中; 文件“ resource://gre/modules/commonjs/sdk/content/worker.js”,第510行,位于worker this._contentWorker = WorkerSandbox(this);中。 文件“ resource://gre/modules/commonjs/sdk/deprecated/traits.js”,行114,在Trait中返回self.constructor.apply(self,arguments)|| 自我 文件“ resource://gre/modules/commonjs/sdk/content/worker.js”,第302行,位于WorkerSandbox中。this._importScripts.apply(this,contentScriptFile); 文件“ resource://gre/modules/commonjs/sdk/content/worker.js”,第361行,以_importScripts加载(this._sandbox,String(uri)); 文件“ resource://gre/modules/commonjs/sdk/loader/sandbox.js”,第47行,在加载返回脚本中Loader.loadSubScript(uri,sandbox,'UTF-8'); 文件“ resource://jid0-gb1orekgm6ay3hjawryzhdrneug-at-jetpack/synesthesia/data/timbre.js”,第1行,为空(函数(t){“使用严格”;函数e(){函数e(t){ for(var e,i = Array(t.byteLength),s = t.BYTES_PER_ELEMENT,n = 0,r = i.length; r> n; ++ n)e = 8 *(n%s),i [ n] =([...]

甚至尝试使用require()导入它,但是它不起作用。 我应该如何导入? 谢谢再见!

根据文档,没有Widget contentScriptFile 还有一个如何创建Widget的问题。 应该是这样,您不应该使用new关键字:

const widgets = require("sdk/widget");
const data = require("sdk/self").data;

var player = widgets.Widget({
  id: "widget",
  label: "Label",
  contentURL: data.url("cat.png")
});

我不确定您要在这里实现什么。 如果您只想在页面中执行脚本,则解决方案是PageMod而不是Widget 如果要使用timbre.js在页面中执行操作。 解决方案是:

  • PageMod用于内容脚本。
  • 使用窗口Widget作为菜单。
  • 使用附加代码和内容脚本之间的通信机制port )发送消息

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM