Messaging API compatibility

Hi is @plasmohq/messaging works on every web browser or only in chrome? I need to work in safari and firefox.
25 Replies
lab
lab•16mo ago
Should work on Safari (tested it before). For Firefox, PR to make it compat is welcome :)
wybran
wybran•16mo ago
On firefox sendToBackground works well in content script but in popup I dont getting return value from backgruond function messages/login.ts
import type { PlasmoMessaging } from "@plasmohq/messaging"
import { fetchAPI } from "~utils/fetchAPI"

const handler: PlasmoMessaging.MessageHandler = async (req, res) => {
const { email, password } = req.body

const response = await fetchAPI('https://MY_API/api/login', {
method: 'POST', body: JSON.stringify({ email, password })
})
console.log(response)
res.send(response)

}

export default handler
import type { PlasmoMessaging } from "@plasmohq/messaging"
import { fetchAPI } from "~utils/fetchAPI"

const handler: PlasmoMessaging.MessageHandler = async (req, res) => {
const { email, password } = req.body

const response = await fetchAPI('https://MY_API/api/login', {
method: 'POST', body: JSON.stringify({ email, password })
})
console.log(response)
res.send(response)

}

export default handler
Popup/index.tsx:
import { sendToBackground } from "@plasmohq/messaging"

function IndexPopup() {

const login = async () => {
const resp = await sendToBackground({
name: "login",
body: { email: "email", password: "pass" }
})
console.log(resp)
return resp
}
return (
<div>
XDD
<button
onClick={login}>
Login
</button>
)}
import { sendToBackground } from "@plasmohq/messaging"

function IndexPopup() {

const login = async () => {
const resp = await sendToBackground({
name: "login",
body: { email: "email", password: "pass" }
})
console.log(resp)
return resp
}
return (
<div>
XDD
<button
onClick={login}>
Login
</button>
)}
When I click login in popup the request is send but console.log(resp) is undefind
Arcane
Arcane•16mo ago
@wybran has reached level 1. GG!
lab
lab•16mo ago
is there any bgsw error logging? tho iirc, bgsw is not yet a thing in ff?...
wybran
wybran•16mo ago
there are no errors so why is working in content script but not in popup 🙃
lab
lab•16mo ago
oh it works with CS but not with popup?
wybran
wybran•16mo ago
yes
lab
lab•16mo ago
the one thing I know about firefox popup is that you can't open its inspect lol...
wybran
wybran•16mo ago
in popup only send message but not getting return data
lab
lab•16mo ago
try doing it manually and see what's the diff :d.... it could be that ff's popup runtime is behind cs runtime xd so popup might be using the callback api meanwhile cs is using the promise api lol that'd be messed up
wybran
wybran•16mo ago
console.log in popup useEffect triggers faster than console.log in background script
lab
lab•16mo ago
hmm, that indicates the API on ff is using callback I suspect that's the case :d.....
wybran
wybran•16mo ago
on chrome and safari it is working
lab
lab•16mo ago
yeah since chrome and safari aligns well on that API but firefox... kinda do their own thing nowaday
wybran
wybran•16mo ago
do you have any ideas how can I fix it?
Want results from more Discord servers?
Add your server