How do I call functions and get the return values from a popup?

I've been trying to put together a simple proof-of-concept for an idea I had to create an extension that could call some functions and get data from a content script running on a page. I can't seem to figure out how to get the communication between the popup and the content script. I keep coming across information that says to either use the underlying chrome.runtime in the content script or use plasmo's messaging, but whenever I try to do any kind of messaging in the content script, I get an error saying that chrome.runtime effectively doesn't exist (trying to access a property of a non-object). Any ideas what I might be doing wrong?
2 Replies
nerdo
nerdoOP•8mo ago
By the way, I noticed that in both the dev and prod manifest.json, there is no content_scripts key where the content.js is specified. I'm not sure what I did wrong. The content script is running but it seems like something is misconfigured
isibbot
isibbot•8mo ago
You need to use the messaging API plasmo provides. https://docs.plasmo.com/framework/messaging#message-flow
Plasmo Docs
Messaging API – Plasmo
The Plasmo messaging API is a powerful tool for sending real-time messages between different parts of your extension.
Want results from more Discord servers?
Add your server