Can you send messages from content scripts in the main world?

I'm kinda lost between just having the following in the content script
const resp = sendToBackgroundViaRelay({
name: "editor"
})
const resp = sendToBackgroundViaRelay({
name: "editor"
})
with an editor.ts handler in background handle it orrrrr, this in the content script and an editor.ts in the background to handle it
relay(
{
name: "editor"
},
async (req) => {
console.log("some message was relayed:", req)

return {
message: "Hello from sandbox"
}
}
)
relay(
{
name: "editor"
},
async (req) => {
console.log("some message was relayed:", req)

return {
message: "Hello from sandbox"
}
}
)
Or something else I'm missing, the other thought I had is you're supposed to have two content scripts, one in the main world and one not then in the one that's not you have
relayMessage({
name: "editor"
})
relayMessage({
name: "editor"
})
Thanks so much!
2 Replies
caleb
calebOP•2y ago
Ooo I got it, it's the one where you have two content scripts
lab
lab•2y ago
Yup
Want results from more Discord servers?
Add your server