We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Am I missing something here? According to the docs (https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/runtime/onMessage), onMessage should always have a third 'sendResponse' function parameter. The code around https://github.com/mozilla/webextension-polyfill/blob/master/src/browser-polyfill.js#L330 suggests that I need to define the listener as following:
browser.runtime.onMessage.addListener((message, sender) => { return new Promise((resolve, reject) => { }) })
Doesn't this break for browsers without the polyfill? (e.g. Firefox/Edge)
The text was updated successfully, but these errors were encountered:
@jvanveen, I think the part you're missing is in the docs, where it says
To send an asynchronous response, there are two options: return true from the event listener. This keeps the sendResponse function valid after the listener returns, so you can call it later. return a Promise from the event listener, and resolve when you have the response (or reject it in case of an error).
To send an asynchronous response, there are two options:
The code you posted is the 2nd option. This works just fine in Firefox, as well as in Chrome with the polyfill.
If you want a more synchronous version:
browser.runtime.onMessage.addListener((message, sender) => { return Promise.resolve("reply"); })
But you are correct that the callback version (sendResponse in the Mozilla docs) does not polyfill correctly.
Sorry, something went wrong.
This appears to be a duplicate of #16 where there is lots of interesting discussion of the issue.
Closing. This was fixed by #97 and will be released in the next version (0.3.0, see #88).
No branches or pull requests
Am I missing something here? According to the docs (https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/runtime/onMessage), onMessage should always have a third 'sendResponse' function parameter. The code around https://github.com/mozilla/webextension-polyfill/blob/master/src/browser-polyfill.js#L330 suggests that I need to define the listener as following:
Doesn't this break for browsers without the polyfill? (e.g. Firefox/Edge)
The text was updated successfully, but these errors were encountered: