You don't need to create the message channel yourself.
I've already added the onMessage.addListener
and sendMessage
methods to the browser-action-jplib. Just read the documentation (generated using cfx sdocs
from docs/browser-action.md).
Use it as follows:
const { data } = require("sdk/self");
var badge = require("browserAction").BrowserAction({
default_icon: data.url("images/icon19.png"),
default_title: "MyAddon",
default_popup: data.url("pages/popup.html")
});
badge.onMessage.addListener(function(message, sender, sendResponse) {
if (message === "test") {
sendResponse("Test recieved");
}
});
Minimal JavaScript code in popup, for the sake of the example:
extension.sendMessage("test", function(message) {
document.body.textContent = message;
});