Popup -> Content Script messaging
After clicking button in the popup I'd like to trigger some function defined in the Content Script. How should I approach it? I was reading the https://docs.plasmo.com/framework/messaging docs page but I don't saw this particular scenario. Should I use native Chrome API in that case? https://developer.chrome.com/docs/extensions/mv3/messaging/
Plasmo Docs
Messaging API β Plasmo
The Plasmo messaging API is a powerful tool for sending real-time messages between different parts of your extension.
Chrome Developers
Chrome Extensions Message passing - Chrome Developers
How to pass messages between extensions and content scripts.
7 Replies
You can use sendToContentScript function from the messagin API - it's undocumented atm xD...
@louisgv hey sorry to bother you but im trying to do same as OP but how exactly do you listen for the message in the content script?
i couldnt find this in the docs
There's a listen function from
plasmo/messaging/messages
but it's pretty much undocumented - feel free to try it out and lmk if it works
@tan(πΒ²)γγ«γcouldnt get that one working but i managed to do it with the basic chrome runtime api i thought there would be a plasmo abstraction of some sort but i guess its unnecessary
@tan(πΒ²)γγ«γ has reached level 1. GG!
yeah since there's.. not much to abstract from IMO xD
the Hi @louisgv I was trying the same. Can you provide an example of sendToContentScript function from the messaging API? I tried but didn't succeed. Alternatively used Chrome runtime api but I need to do same for Firefox and in Firefox runtime api is crashing. Can simple example would be a great help.