Reputation: 11812
I'm trying to write a cross browser extension that is using a background script and a popup that cross-communicate:
In the background script:
class Listener{
listen(cb){
chrome.runtime.onMessage.addListener((transmission, sender, messageResponseFn) => {
cb(transmission, messageResponseFn);
return true;
});
}
}
export default new Listener();
In the popup:
class Emitter{
send(message, payload){
return new Promise((resolve, reject) => {
chrome.runtime.sendMessage({ message, payload }, (responseMessage) => {
resolve(responseMessage);
});
});
}
}
export default new Emitter();
This works as expected in Chrome, yet in Firefox the sent response (the function is called correctly and does not throw) will never arrive in my Emitter
. Am I using this API wrong? Are there any differences between Firefox and Chrome that I am not aware of? From what I read in the docs the runtime.sendMessage
API should be fully supported.
FWIW, here's an example repository demonstrating the issue: https://github.com/m90/firefox-webextension-issue
Upvotes: 0
Views: 1679
Reputation: 11812
This is a confirmed bug in the WebExtension API so there's not much to do about it.
Upvotes: 1