Sleigh
Sleigh
PD🧩 Plasmo Developers
Created by Sleigh on 10/16/2023 in #👟framework
Multiple Content Scripts on One Page Not Working As Expected
No description
7 replies
PD🧩 Plasmo Developers
Created by Sleigh on 3/23/2023 in #🔰newbie
No Response from sendToBackground()
Hi there, plasmo noob here. Trying to call a firebase function on the click of a button from a content-script. Read docs on using the messaging api with a background worker. Think I set it all up correctly but not getting any response at all from the sendToBackground() method. Here's some snippets.
// Adding the event listener to my new injected button to call generate
newButton.addEventListener("click", async () => {
console.log("I have been clicked")

const response = await sendToBackground({
name: "generate"
})

console.log("Response " + response)
}
// Adding the event listener to my new injected button to call generate
newButton.addEventListener("click", async () => {
console.log("I have been clicked")

const response = await sendToBackground({
name: "generate"
})

console.log("Response " + response)
}

// background/test/generate.ts

import type { PlasmoMessaging } from "@plasmohq/messaging"
import { httpsCallable } from "firebase/functions"

import { functions } from "~firebase"

const handler: PlasmoMessaging.MessageHandler = async (req, res) => {
const generateMessage = httpsCallable<any, any>(
functions,
"generateMessage"
)

console.log("Calling the method")

const response = await generateMessage()

console.log("Response " + JSON.stringify(response))

res.send({
response
})
}

export default handler

// background/test/generate.ts

import type { PlasmoMessaging } from "@plasmohq/messaging"
import { httpsCallable } from "firebase/functions"

import { functions } from "~firebase"

const handler: PlasmoMessaging.MessageHandler = async (req, res) => {
const generateMessage = httpsCallable<any, any>(
functions,
"generateMessage"
)

console.log("Calling the method")

const response = await generateMessage()

console.log("Response " + JSON.stringify(response))

res.send({
response
})
}

export default handler
Again, I don't see any logs, when I execute this. Any ideas what I messed up?
6 replies