Repository navigation
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 ? |
|
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. |
|
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 |
|
I think we can find the perfect example here |
Uh oh!
There was an error while loading. Please reload this page.
Is there any documentation or example of using
sendToContentScriptof@plasmohq/messagingAll reactions