firefox插件包括timbre.js

firefox add-on include timbre.js

本文关键字:js timbre 包括 插件 firefox      更新时间:2023-09-26

我试图为firefox做一个扩展,我需要使用timbre.js(http://mohayonao.github.io/timbre.js/),所以我想把它包含在contentScriptFile中,并以这种方式在test.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,in_on准备自我_onInit();文件"resource://gre/modules/commonjs/sdk/widget.js",第803行,为null这个_initSymbiont();文件"resource://gre/modules/commonjs/sdk/content/symbiont.js",第200行,在Symbiont<中_onnit这个_initWorker({window:this_frame.contentWindow});文件"resource://gre/modules/commonjs/sdk/content/worker.js",第510行,在工人这个_contentWorker=WorkerSandbox(this);文件"resource://gre/modules/commonjs/sdk/deprecated/traits.js",第114行,在Traitreturn self.constructor.apply(self,arguments)||self_平民的文件"resource://gre/modules/commonjs/sdk/content/worker.js",行302,在WorkerSandbox中这个_importScripts.apply(this,contentScriptFile);文件"resource://gre/modules/commonjs/sdk/content/worker.js",第361行,在_导入脚本load(this.sandbox,String(uri));文件"resource://gre/modules/commonjs/sdk/loader/sandbox.js",第47行,在负载return scriptLoader.loadSubScript(uri,沙箱,UTF-8);文件"resource://jid0-gb1orekgm6ay3hjawryzhdrneug-at-jetpack/synesthesia/data/timbre.js",第1行,为空(函数(t){"use strict";函数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)发送消息