Skip to content
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

Error with tabs.sendMessage when no response #75

Open
Dreamsorcerer opened this issue Nov 12, 2017 · 4 comments
Open

Error with tabs.sendMessage when no response #75

Dreamsorcerer opened this issue Nov 12, 2017 · 4 comments

Comments

@Dreamsorcerer
Copy link

A Promise that will be fulfilled with the JSON response object sent by the handler of the message in the content script, or with no arguments if the content script did not send a response.

When nothing is returned from the content script, Chrome throws an error. The polyfill should presumably implicitly return something if the content script doesn't, or otherwise suppress this error.

@LilDevil
Copy link

I can't comment on whether this a bug in the polyfill but I've found that you can make the error go away by adding the following to the end of your message handler.

return false;

@Dreamsorcerer
Copy link
Author

Yes, that's what I've done in the Chrome version. But, the goal of the polyfill is to allow web extensions to run unchanged, hence the bug report that it should do this implicitly.

@PedroS11
Copy link

I have the same issue with browser.runtime.sendMessage. With Firefox, I don't receive the response too as I can see from the issues list, it's still a bug to be fixed

@dessant
Copy link

dessant commented Apr 11, 2022

There are also other browser bugs around the API, the promise returned by runtime.sendMessage will never resolve nor reject if you return undefined from the background page message listener in Safari 15, so I always send a null response when the reply would be undefined, or when there is nothing to return to the caller.

Though these bugs should be fixed in browsers. Developers might type check message responses, so the API behavior should not be changed by the polyfill to hide implementation bugs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants