firefox附加组件包括timbre.js

时间:2013-07-16 10:40:29

标签: javascript firefox firefox-addon

我试图为firefox做一个扩展,我需要使用timbre.js(http://mohayonao.github.io/timbre.js/),所以我想把它包含在contentScriptFile中并以这种方式在test.js文件中使用它: / p>

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:失败回溯(最近一次调用最后一次):   文件“资源://gre/modules/commonjs/sdk/content/symbiont.js”,行   172,在_onReady中       self._onInit();文件“resource://gre/modules/commonjs/sdk/widget.js”,第803行,null       this._initSymbiont();文件“resource://gre/modules/commonjs/sdk/content/symbiont.js”,第200行,   在Symbiont< ._ onInit中       this._initWorker({window:this._frame.contentWindow});文件“resource://gre/modules/commonjs/sdk/content/worker.js”,第510行,in   工人       this._contentWorker = WorkerSandbox(this);文件“资源://gre/modules/commonjs/sdk/deprecated/traits.js”,第114行,   在特质       return self.constructor.apply(self,arguments)|| self._public;文件“资源://gre/modules/commonjs/sdk/content/worker.js”,行   302,在WorkerSandbox中       this._importScripts.apply(this,contentScriptFile);文件“resource://gre/modules/commonjs/sdk/content/worker.js”,第361行,in   _importScripts       load(this._sandbox,String(uri));文件“resource://gre/modules/commonjs/sdk/loader/sandbox.js”,第47行,in   加载       return scriptLoader.loadSubScript(uri,sandbox,'UTF-8');文件“resource://jid0-gb1orekgm6ay3hjawryzhdrneug-at-jetpack/synesthesia/data/timbre.js”,   第1行,null       (function(t){“use strict”; function e(){function e(t){for(var e,i = Array(t.byteLength),s = t.BYTES_PER_ELEMENT,n = 0,r = i。长度; R将N; ++ n)的E = 8 *(N%S)中,i [N] =(   [...]

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

1 个答案:

答案 0 :(得分:0)

根据文档,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作为菜单。
  • 使用插件代码和内容脚本之间的communication mechanismport)发送消息