-
What happened?Message flow requires extension ID after sending a message from the content script to the background script. The content script has injected a function into the 'MAIN' world that triggers a Uncaught (in promise) TypeError: Error in invocation of runtime. sendMessage(optional string extensionId, any message, optional object options, optional function callback): chrome.runtime. sendMessage) called from a webpage must specify an I get this error on both Edge and Brave. Using both mac and windows OS. VersionLatest What OS are you seeing the problem on?Other What browsers are you seeing the problem on?No response Relevant log output// Error
Promise {<rejected>: TypeError: Error in invocation of runtime.sendMessage(optional string extensionId, any message, opt…}
TypeError: Error in invocation of runtime.sendMessage(optional string extensionId, any message, optional object options, optional function callback): chrome.runtime.sendMessage() called from a webpage must specify an Extension ID (string) for its first argument. at x (chrome-extension://aofahlffpoepdbbebokimmfmggadbldm/window-main.ef1983a5.js:450:24) at Agent.findWebtoon (chrome-extension://aofahlffpoepdbbebokimmfmggadbldm/window-main.ef1983a5.js:382:60)
"Error in invocation of runtime.sendMessage(optional string extensionId, any message, optional object options, optional function callback): chrome.runtime.sendMessage() called from a webpage must specify an Extension ID (string) for its first argument."
"TypeError: Error in invocation of runtime.sendMessage(optional string extensionId, any message, optional object options, optional function callback): chrome.runtime.sendMessage() called from a webpage must specify an Extension ID (string) for its first argument.\n at x (chrome-extension://aofahlffpoepdbbebokimmfmggadbldm/window-main.ef1983a5.js:450:24)\n at Agent.findWebtoon (chrome-extension://aofahlffpoepdbbebokimmfmggadbldm/window-main.ef1983a5.js:382:60)
// /contents/window-main.ts
import type { PlasmoCSConfig } from "plasmo"
import { Agent } from "~communication/agent"
export const config: PlasmoCSConfig = {
world: "MAIN"
}
window.anlanther = {
webtoon: new Agent()
}
// /agent.ts
import { sendToBackground } from "@plasmohq/messaging"
export class Agent {
async findWebtoon(name: string): Promise<any> {
const query = `` // tested graphql query
const variables = {
name
}
const test = await sendToBackground({
name: "fetch",
body: {
query,
variables
}
})
return test
}
}
// /background/messages/fetch.ts
import type { PlasmoMessaging } from "@plasmohq/messaging"
const handler: PlasmoMessaging.MessageHandler = async (req, res) => {
const message = await graphql(req.body.query, req.body.variables)
res.send(message)
}
const graphql = async (payload, variables) => {} // graphql fetch logic
export default handler
// On webpage psudocode
<button click={() => window.anlanther.webtoon.findWebtoon("Relife Player")}>Test</button> (OPTIONAL) Contribution
Code of Conduct
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
You cannot call Note that the pub/sub API uses externally_connectable feature, which requires a specific website url as a target. |
Beta Was this translation helpful? Give feedback.
You cannot call
sendToBackground
in main world - the "main world" concept is related to extension sandbox isolation. You will need to either use the relay API or the pub/sub API abstraction to route message from main world to your extension.Note that the pub/sub API uses externally_connectable feature, which requires a specific website url as a target.