Is there any example of using sendToContentScript #486
Replies: 5 comments
-
I'm also looking for documentation or code example. Did you manage to find any @gypsicoder ? |
Beta Was this translation helpful? Give feedback.
-
I didn't find yet @PixellUp |
Beta Was this translation helpful? Give feedback.
-
To use sendToContentScript to send from background message to context you can send a message in the following style // Send a message to the content script
sendToContentScript({
body: {
message: "Hello from the background script",
},
name: 'context name'
});
However, I only manage to receive the message using native chrome runtime like chrome.runtime.onMessage.addListener(function (message) {
if (message.name === "context name") {
console.log("context name", message.body);
}
console.log("[APP] Received message from background script:", message);
}); I'll much prefer if there is a way via plasmo to detect and use a universal runtime for other browsers such as Firefox and Safari, instead of hardcoding chrome runtime to have a much easier way to build for other browsers. |
Beta Was this translation helpful? Give feedback.
-
I think this repo has what you want. https://github.com/PlasmoHQ/ghw-workshop/blob/main/background.ts#L35 https://github.com/PlasmoHQ/ghw-workshop/blob/main/content.tsx#L16 |
Beta Was this translation helpful? Give feedback.
-
I think we can find the perfect example here |
Beta Was this translation helpful? Give feedback.
-
Is there any documentation or example of using
sendToContentScript
of@plasmohq/messaging
Beta Was this translation helpful? Give feedback.
All reactions