Reputation: 11
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!
Upvotes: 0
Views: 238
Reputation: 11757
According to the documentation, there is no contentScriptFile
for Widget
. There is also a problem how you create the Widget
. It should be something like this and you should not use the new
keyword:
const widgets = require("sdk/widget");
const data = require("sdk/self").data;
var player = widgets.Widget({
id: "widget",
label: "Label",
contentURL: data.url("cat.png")
});
I'm not sure what you are trying to achieve here. If you simply want to execute a script in the page, your solution is a PageMod
and not Widget
. If you want to execute an action in your page using timbre.js
. The solution would be to:
PageMod
for the content scripts.Widget
for the menu.port
) between addon code and content scripts to send messages.Upvotes: 0