2013-07-16 53 views
0

我試圖爲Firefox做一個擴展,我需要使用timbre.js(http://mohayonao.github.io/timbre.js/),所以我想將它包含在contentScriptFile中並在test.js文件中使用它這種方式:firefox add-on include timbre.js

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

的問題是,它不會因爲這個加載:

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]=( [...]

即使試圖導入它的require(),但它不工作。 我應該如何導入它? 謝謝再見!

回答

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)發送消息
+0

contentScriptFile是Widget的選項。 – pondermatic