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"
          })

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"
     }
   }
 )


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"
})


Thanks so much!
Was this page helpful?