【问题标题】:firefox add-on include timbre.jsfirefox 插件包括 timbre.js
【发布时间】:2013-07-14 12:10:48
【问题描述】:

我正在尝试为 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,在_onReady self._onInit();文件“resource://gre/modules/commonjs/sdk/widget.js”,第 803 行,为空 this._initSymbiont();文件“resource://gre/modules/commonjs/sdk/content/symbiont.js”,第 200 行, 在共生<._oninit this._initworker this._contentworker="WorkerSandbox(this);文件“resource://gre/modules/commonjs/sdk/deprecated/traits.js”,第" return self.constructor.apply arguments self._public workersandbox this._importscripts.apply contentscriptfile _importscripts scriptloader.loadsubscript sandbox e>n;++n)e=8*(n%s),i[n]=( [...]

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

【问题讨论】:

    标签: javascript firefox firefox-addon


    【解决方案1】:

    根据文档,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 mechanism (port) 发送消息

    【讨论】:

    • contentScriptFile 是 Widget 的一个选项。
    猜你喜欢
    • 2011-07-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多