-
Notifications
You must be signed in to change notification settings - Fork 215
New issue
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
Support multiple runtime.onMessage listeners that do not return results #23
Conversation
Note that if none of the handlers return a non-undefined value, then it is up to the garbage collector to clean the callback (if possible) and then ultimately trigger a response. Can you verify that the callback at the other end (the caller of And you don't need to base your PR on mine, I don't touch the promise part of the onMessage handler. Furthermore, the PR title and commit title do not actually reflect the effect of the change, please choose a more accurate title. Thanks! |
Rewrote PR to not build off of @Rob--W 's PR. I will test to see if callback is called if all of the handlers undefined |
@Rob--W you are correct, if no listener returns a non-undefined result then the callback will not be called. Eventually the caller will throw an exception: "The message port closed before a response was received." I'm not yet sure how to fix this though, or even if its possible. |
That behavior looks reasonable given the conflicting constraints. The promise rejection matches Firefox's implementation too (in Firefox the error is "No handler returned a response"). If an extension dev wishes to explicitly send no response (so a fulfilled promise instead of a rejected one), then they can yield |
For what its worth the Firefox implementation seems to treat a promise that resolves with Here's a test I just did on FF 51.0.1: background.js:
content.js:
background:
content:
|
Unfortunately this PR will be a breaking change for existing extensions that may only use a single listener. If it returns a Promise that yields undefined, the background script will have a delay (I believe as you said until the GC picks it up) and then throw an exception. |
Hi @collinsauve, in #115 we added a test case ( webextension-polyfill/test/fixtures/multiple-onmessage-listeners-extension/background.js Lines 28 to 30 in 5d186ba
undefined is sent as a response, the sender receives it as null , on Firefox it is received as undefined ).
I haven't seen the I'm wondering if the test case is missing something from the scenario that allowed you to trigger it, or if the changes applied recently to the onMessage listener wrapper may have changed the behavior that was triggering it. I'm closing this PR in the meantime, preventing |
When multiple listeners are setup, if they are both async or return promises but those promises do not actually return something when resolved, it will throw the following:
This should be able to be reproduced as follows:
The listeners should not call sendResponse if there is no result from a promise.