Page workers, like tab attaching and unlike pageMods, don't have an onAttach
function. Nor do they have an onReady
, since the contentScriptFile is automatically attached when the HTML is ready.
main.js
var worker = pageWorkers.Page({
contentURL: self.data.url("html/worker.html")
});
worker.port.on("message", function() {
console.log("Message received");
});
//If your events have the same name then they're the same event,
//irrespective of arguments passed
worker.port.on("message1", function(message) {
console.log("Message received1");
});
worker.js
console.log("trying to emit message");
addon.port.emit("message");
console.log("trying to emit message1");
addon.port.emit("message1", "value");