如何从 Firefox 中的 contentScript 访问变量?

How to access variable from contentScript in firefox?

我想从 contentScriptFile 打开新标签,但我无法访问标签变量。

我在 Firefox 高级 API 中使用了 tabs

//index.js
var self = require("sdk/self");
var cm = require("sdk/context-menu");
var tabs = require("sdk/tabs");

cm.Item({
    label: "Test",
    contentScriptFile : self.data.url("script.js") 
});




//script.js
self.on(
    'click',
    function (node, data) {
        tabs.open('http://example.com/'); //Not work :-(
    }
);

已解决 'onMessage'

的问题
//index.js
var self = require("sdk/self");
var cm = require("sdk/context-menu");
var tabs = require("sdk/tabs");

var menuItem = cm.Item({
label: "Test",
context: cm.SelectionContext(),
    //We can use contentScript for simple app
    contentScriptFile: self.data.url("script.js"),
    onMessage: function () {
        tabs.open('http://example.com/'); 
    }
});


//script.js
self.on("click", self.postMessage);