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

runtime.sendMessage doesn't pass callback to onMessage listeners #307

Closed
kmarple1 opened this issue Apr 22, 2021 · 4 comments
Closed

runtime.sendMessage doesn't pass callback to onMessage listeners #307

kmarple1 opened this issue Apr 22, 2021 · 4 comments

Comments

@kmarple1
Copy link

I'm attempting to test my onMessage listeners, but I keep getting the error TypeError: sendResponse is not a function. It appears that the implementation of runtime.sendMessage accepts a callback as the second argument, but doesn't actually pass it to the listener.

My workaround thus far has been to pass a default value to my listeners, ex:
browser.runtime.onMessage.addListener((request, sender, sendResponse = () => {}) => {

While this gets rid of the error, not being able to check the results passed to the callback make the test almost useless.

@Rob--W
Copy link
Member

Rob--W commented Apr 22, 2021

How are you testing this?

The current version of the polyfill passes the sendResponse listener at

result = listener(message, sender, wrappedSendResponse);
This behavior was introduced in version 0.3.0 and is still present in the latest version (0.8.0). Are you using the latest version of the polyfill?

@kmarple1
Copy link
Author

OK, I actually posted this in the wrong repo; I meant to post it to clarkbw/jest-webextension-mock. If I try to use the polyfill directly from jest, I always get the error This script should only be loaded in a browser extension.

@Rob--W
Copy link
Member

Rob--W commented Apr 22, 2021

Closing since this is bug report is unrelated to this project and a bug report has been filed at clarkbw/jest-webextension-mock#136

@escapedcat
Copy link

Just for others ending up here, this helped me: #218 (comment)

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

3 participants