我在Firefox插件开发中遇到一个奇怪的事情:我编写这样的代码(我将注释代码从chrome扩展转换为Firefox插件代码):
function sendStoreIdentitiesMessage(identities, remember){
console.log("Storing identities: "+identities.length);
if(remember==null){
remember=false;
}
//extension.sendMessage({type:"save.identities", identities:identities, remember:remember}, function(response) {
// identitiesNum=identities.length;
// identitiesDate=new Date();
// sendGetPageIdsMessage(function(){showCodeImageSuccess();});
//});
self.postMessage({type:"save.identities", identities:identities, remember:remember});
self.port.on("response.save.identities",function(response){
identitiesNum=identities.length;
identitiesDate=new Date();
sendGetPageIdsMessage(function(){showCodeImageSuccess();});
});
}
当我使用Addon Builder编译它时,它会收到“Error: NS_ERROR_XPC_NOT_ENOUGH_ARGS: Not enough arguments [nsIDOMWindow.postMessage]
”错误。然后我改变代码:
function sendStoreIdentitiesMessage(identities, remember){
console.log("Storing identities: "+identities.length);
if(remember==null){
remember=false;
}
//extension.sendMessage({type:"save.identities", identities:identities, remember:remember}, function(response) {
// identitiesNum=identities.length;
// identitiesDate=new Date();
// sendGetPageIdsMessage(function(){showCodeImageSuccess();});
//});
self.port.emit("message",{type:"save.identities", identities:identities, remember:remember});
self.port.on("response.save.identities",function(response){
identitiesNum=identities.length;
identitiesDate=new Date();
sendGetPageIdsMessage(function(){showCodeImageSuccess();});
});
}
我收到了另一个错误:TypeError: self.port is undefined
。那么,怎么了?
感谢。