samson
samson
Explore posts from servers
PD🧩 Plasmo Developers
Created by samson on 12/22/2023 in #🔰newbie
Receiving end does not exist.
Hey there, new Plasmo user here. I'm trying to pull some information from the DOM (of the currently active tab) and display it in my extension. Should be simple... I'm getting Error: Could not establish connection. Receiving end does not exist. when calling sendToContentScript. I couldn't find any documentation for this function, so hoping you can point me to the right direction. I refreshed all tabs/ reloaded the extension, so I think the error is due to me not understanding how messaging in Plasmo works.. popup.tsx
const handleClick = async () => {
//call function inside content script
const res = await sendToContentScript({ name: "getFields" })
console.log("result is", res)
}
const handleClick = async () => {
//call function inside content script
const res = await sendToContentScript({ name: "getFields" })
console.log("result is", res)
}
contents/getFields.ts
import { useMessage } from "@plasmohq/messaging/hook"

export default function getFields() {
useMessage<string, string[]>(async (req, res) => {
const { name } = req
if (name === "getFields") {
const fields = Array.from(document.body.querySelectorAll("input")).map(
(input) => {
return input.name
}
)
res.send({ ...fields })
}
})
}
import { useMessage } from "@plasmohq/messaging/hook"

export default function getFields() {
useMessage<string, string[]>(async (req, res) => {
const { name } = req
if (name === "getFields") {
const fields = Array.from(document.body.querySelectorAll("input")).map(
(input) => {
return input.name
}
)
res.send({ ...fields })
}
})
}
18 replies