Messaging-chrome.runtime.sendMessage() called from a webpage must specify an ExtensionID (string)

TypeError:error invocation of runtime.sendMessage(optional string extensionId, any message....): chrome.runtime.sendMessage() called from a webpage must specify an ExtensionID (string) for its first argument.

I'm using sendToBackground from a function injected into the webpage from the content script through the 'MAIN' world. The website is also already is listed under "externally_connectable" and have an async API call set up in a file under background/messages.

The code is like this:

// function injected to window object
async getResult(name: string) {
    const resp = await sendToBackground({
        name: 'get-result',
        body: { name }
    })

    return resp;
}

// /background/messages/get-result.ts
const handler: Plasmo.MessageHandler = async (req, res) => {
    const message = await someFunc(req.body.name)

    res.send(message)
}

export default handler;


I have the extension ID in my .env. Am I supposed to insert it somewhere? sendToBackground doesn't seem to have any other arguements I can pass.
Was this page helpful?