Closed andrefgneves closed 4 months ago
You can't send a message directly from a popup to a content script, if that's what you're trying to do. The messaging library is a simple wrapper around the web extension APIs, and that's not allowed.
You have to forward it through the background.
popup -> background -> content-script
. Same thing if it's the other way around.
Here's an example of using the background to forward messages between frames of the same tab, which is similar to what you're attempting to accomplish (frame n -> background -> frame 0
).
https://github.com/search?q=repo%3Aanime-skip%2Fplayer%20getEpisodeInfoFromHelper&type=code
You can do this with defineExtensionMessaging
, no need to expose the generic version.
Thanks @aklinker1, that makes sense.
Maybe I missed it, but with
@webext-core/messaging
there seems to be no way to register the listeners on a content script. I have a use case where I want my popup to get some data from content script running on the active window/tab. ExposingdefineGenericMessanging
would allow me to create a custom messaging wrapper and benefit from everything else that@webext-core/messaging
provides. I'm using@webext-core/proxy-service
to talk to the bg script, and I'd also like to keep all the messaging APIs consistent.