According to the Browser compatibility chart for runtime.sendMessage(), this API is compatible across Chrome and Firefox. I’m not seeing that to be the case though – the Firefox version seems to return a Promise where the Chrome version seems to be essentially a void return (and needs a callback function to use it asynchronously).
Is the difference expected behavior and something that should be added as a note to the page?
Aside from the promise thing, it works pretty much the same. I haven’t had issues with differences with Chrome v Firefox. But v Edge I find some issues, can’t remember them right now i abstracted it and forgot about it.
Notice also that you can use callbacks in order to be compatible with every browsers.
//Promise --> works only in Firefox
browser.runtime.sendMessage(message).then(function(response){
console.log(response);
});
is equivalent to
//Callback --> works in Firefox, Chrome and Opera
var browser = browser || chrome;
browser.runtime.sendMessage(message,function(response){
console.log(response);
});