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
Should work on Safari (tested it before). For Firefox, PR to make it compat is welcome :)
On firefox
sendToBackground
works well in content script but in popup I dont getting return value from backgruond function
messages/login.ts
Popup/index.tsx:
When I click login in popup the request is send but console.log(resp) is undefind@wybran has reached level 1. GG!
is there any bgsw error logging?
tho iirc, bgsw is not yet a thing in ff?...
there are no errors
so why is working in content script but not in popup 🙃
oh it works with CS but not with popup?
yes
the one thing I know about firefox popup is that you can't open its inspect lol...
in popup only send message but not getting return data
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
console.log in popup useEffect triggers faster than console.log in background script
hmm, that indicates the API on ff is using callback
I suspect that's the case :d.....
on chrome and safari it is working
yeah since chrome and safari aligns well on that API
but firefox... kinda do their own thing nowaday
do you have any ideas how can I fix it?
@wybran has reached level 2. GG!
try manually call the message handler with a browser.runtime.sendMessage and see if that API works
(you will need to dig a bit into ff's message API)
how can i access browser in react?
oh you can just do globalThis.browser
see the source code for messaging API for the detail of how it works internally
but basically we wrap the sendMessage calls
this code works in firefox but not in chrome:
oh i found couse:
For Firefox:
For chrome and safari:
how can i detect in the code that it should use browser, not chrome in firefox
does browser.runtime.sendMessage works in FF?
yes
cool beans, let me make a hotfix
Just released 0.3.2
@wybran can you try it out and see if it fix the issue
(the version is for messaging API)
omg thanks a lot
working on chrome and firefox now
safari also work
cool beans