javascript events - Firefox addon: Why the self.port in the panel's contentscript is undefined? -
i meet strange thing firefox addon development:i write code this(i convert commented code chrome extension firefox addon code ):
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();}); }); }
when compile addon builder,it gets "error: ns_error_xpc_not_enough_args: not enough arguments [nsidomwindow.postmessage]
" error. change code this:
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();}); }); }
i got error:typeerror: self.port undefined
. so, what's wrong? thanks.
change self
addon
.detailed document here.
Comments
Post a Comment