我在 main.js 代码上使用 port.emit 时遇到了一些问题。
我尝试了很多不同的方法来做到这一点,但都没有成功。这是我的主要代码:
// main.js
var tabs = require("sdk/tabs"); //
//var data = require("sdk/self").data; //acrescenta a pasta data
var { ToggleButton } = require("sdk/ui/button/toggle");
var dadosCopiados=[];
var worker1;
var worker2;
var self = require("sdk/self");
var button = ToggleButton({
id: "copiadorDeDadosDeAcesso",
label: "Copiador de Dados de Acesso",
icon: {
"16": "./icon-16.png",
"32": "./icon-32.png",
"64": "./icon-64.png"
},
onChange: function(state) {
if(state.checked==true){
worker1 = tabs.activeTab.attach({
contentScriptFile: self.data.url("copiadorDeDados.js")
});
worker1.port.on("dadosDeAcesso", function processaDadosDeAcesso(dados) {
console.log(dados[0]);
console.log(dados[1]);
//console.log(worker);
});
}
else{
worker2 = tabs.activeTab.attach({
contentScriptFile: self.data.url("coladorDeDados.js")
});
worker2.port.emit("teste","my message");
}
}
});
port.on 命令正在工作。当它通过“port.emit”时,我在命令提示符中收到此错误:
console.error:
JPM [error] Message: TypeError: this.sandbox is undefined
Stack:
receive@resource://gre/modules/commonjs/toolkit/loader.js -> resource://gre/
modules/commonjs/sdk/content/worker-child.js:75:7
emitOnObject@resource://gre/modules/commonjs/toolkit/loader.js -> resource://gre
/modules/commonjs/sdk/event/core.js:112:9
emit@resource://gre/modules/commonjs/toolkit/loader.js -> resource://gre/modules
/commonjs/sdk/event/core.js:89:38
processMessageReceived@resource://gre/modules/commonjs/toolkit/loader.js -> reso
urce://gre/modules/commonjs/sdk/remote/child.js:54:38
openModalWindow@resource://gre/components/nsPrompter.js:370:5
ModalPrompter.prototype.openPrompt@resource://gre/components/nsPrompter.js:553:9
ModalPrompter.prototype.alert@resource://gre/components/nsPrompter.js:605:9
@resource://gre/modules/commonjs/toolkit/loader.js -> resource://gre/modules/com
monjs/sdk/loader/sandbox.js -> resource://myaddon/data/coladorDeDados.js:2:1
load@resource://gre/modules/commonjs/toolkit/loader.js -> resource://gre/modules
/commonjs/sdk/loader/sandbox.js:66:12
importScripts@resource://gre/modules/commonjs/toolkit/loader.js -> resource://gr
e/modules/commonjs/sdk/content/sandbox.js:313:9
WorkerSandbox@resource://gre/modules/commonjs/toolkit/loader.js -> resource://gr
e/modules/commonjs/sdk/content/sandbox.js:275:1
constructor@resource://gre/modules/commonjs/toolkit/loader.js -> resource://gre/
modules/commonjs/sdk/core/heritage.js:146:23
initialize@resource://gre/modules/commonjs/toolkit/loader.js -> resource://gre/m
odules/commonjs/sdk/content/worker-child.js:52:20
constructor@resource://gre/modules/commonjs/toolkit/loader.js -> resource://gre/
modules/commonjs/sdk/core/heritage.js:146:23
@resource://gre/modules/commonjs/toolkit/loader.js -> resource://gre/modules/com
monjs/sdk/content/worker-child.js:140:16
emitOnObject@resource://gre/modules/commonjs/toolkit/loader.js -> resource://gre
/modules/commonjs/sdk/event/core.js:112:9
emit@resource://gre/modules/commonjs/toolkit/loader.js -> resource://gre/modules
/commonjs/sdk/event/core.js:89:38
processMessageReceived@resource://gre/modules/commonjs/toolkit/loader.js -> reso
urce://gre/modules/commonjs/sdk/remote/child.js:54:38
我是初学者,这是我的第一个插件,我知道这应该是一个简单的问题,但我无法解决这个问题。此外,没有我的语言(葡萄牙语)的文档。