0

I was trying to make an extension for firefox and I need to use timbre.js (http://mohayonao.github.io/timbre.js/), so I thought to include it in the contentScriptFile and use it in the test.js file this way:

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

The problem is that it won't load because of this:

Timestamp: 16. 07. 13 12:35:33 Error: addon_name: An exception occurred. NS_ERROR_FAILURE: Failure Traceback (most recent call last): File "resource://gre/modules/commonjs/sdk/content/symbiont.js", line 172, in _onReady self._onInit(); File "resource://gre/modules/commonjs/sdk/widget.js", line 803, in null this._initSymbiont(); File "resource://gre/modules/commonjs/sdk/content/symbiont.js", line 200, in Symbiont<._onInit this._initWorker({ window: this._frame.contentWindow }); File "resource://gre/modules/commonjs/sdk/content/worker.js", line 510, in Worker this._contentWorker = WorkerSandbox(this); File "resource://gre/modules/commonjs/sdk/deprecated/traits.js", line 114, in Trait return self.constructor.apply(self, arguments) || self._public; File "resource://gre/modules/commonjs/sdk/content/worker.js", line 302, in WorkerSandbox this._importScripts.apply(this, contentScriptFile); File "resource://gre/modules/commonjs/sdk/content/worker.js", line 361, in _importScripts load(this._sandbox, String(uri)); File "resource://gre/modules/commonjs/sdk/loader/sandbox.js", line 47, in load return scriptLoader.loadSubScript(uri, sandbox, 'UTF-8'); File "resource://jid0-gb1orekgm6ay3hjawryzhdrneug-at-jetpack/synesthesia/data/timbre.js", line 1, in 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.length;r>n;++n)e=8*(n%s),i[n]=( [...]

Even tried importing it with require() but it doesn't works. How should I import it? Thanks Bye!

4

1 に答える 1

0

ドキュメントによると、contentScriptFileforはありませんWidget。の作り方にも問題があります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
于 2013-07-19T04:00:55.187 に答える