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
lab
labβ€’2y ago
You can use sendToContentScript function from the messagin API - it's undocumented atm xD...
tan(π›˜Β²)γƒγƒ«γƒŽ
@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
lab
labβ€’16mo ago
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(π›˜Β²)γƒγƒ«γƒŽ
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
Arcane
Arcaneβ€’16mo ago
@tan(π›˜Β²)γƒγƒ«γƒŽ has reached level 1. GG!
lab
labβ€’16mo ago
yeah since there's.. not much to abstract from IMO xD
nomanmajeed
nomanmajeedβ€’16mo ago
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.
Want results from more Discord servers?
Add your server