0

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

satanas
  • 706
  • 7
  • 11
m90
  • 11,434
  • 13
  • 62
  • 112
  • 1
    Probably related [bugfix](https://bugzilla.mozilla.org/show_bug.cgi?id=1202481) (FF44). Also try asking on [Mozilla addon dev forum](https://discourse.mozilla-community.org/c/add-ons/development). – wOxxOm Nov 17 '15 at 17:32
  • Ok, thanks, will try asking on the forum, too. – m90 Nov 17 '15 at 18:48

1 Answers1

1

This is a confirmed bug in the WebExtension API so there's not much to do about it.

m90
  • 11,434
  • 13
  • 62
  • 112