Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] sendViaRelay works in Chrome but not Firefox #445

Closed
2 tasks done
kenkantzer-truss opened this issue Feb 15, 2023 · 5 comments
Closed
2 tasks done

[BUG] sendViaRelay works in Chrome but not Firefox #445

kenkantzer-truss opened this issue Feb 15, 2023 · 5 comments
Labels
bug Something isn't working

Comments

@kenkantzer-truss
Copy link

What happened?

Firstly, thanks for making this framework - I have a chrome extension, works great.

I'm trying to port the extension to firefox. I've narrowed down the issue to a hanging call to @plasmohq/messaging:

var resp = await sendViaRelay({
      name: "get-email"
    });

As context, I'm calling sendViaRelay within our web app, which is within an iframe, inside of popup.ts:

import { useState } from "react"
import { sendToBackground } from "@plasmohq/messaging"

function IndexPopup() {
    const [data, setData] = useState("")

    return (
        <div>
            <iframe style={{ margin:0, padding: 0, border: "none", height: "580px", width: "431px" }} src={process.env.PLASMO_PUBLIC_IFRAME_DEFAULT_OPEN_PATH}></iframe>
        </div>
    )
}

export default IndexPopup

This is working in Chrome (the only trick there was making sure to set all_frames: true), but for some reason, Firefox doesn't seem to like sendViaRelay (I'd show a console log error message, but sadly, firefox doesn't allow you to see console messages for iframes within popup - makes this more challenging!).

Is sendViaRelay and firefox not playing nice a known thing?

Version

Latest

What OS are you seeing the problem on?

MacOSX

What browsers are you seeing the problem on?

Firefox

Relevant log output

I'd show a console log error message, but sadly, firefox doesn't allow you to see console messages for iframes within popup - makes this more challenging!

(OPTIONAL) Contact Details

[email protected]

Code of Conduct

  • I agree to follow this project's Code of Conduct
  • I checked the current issues for duplicate problems.
@kenkantzer-truss kenkantzer-truss added the bug Something isn't working label Feb 15, 2023
@louisgv
Copy link
Contributor

louisgv commented Feb 18, 2023

Is sendViaRelay and firefox not playing nice a known thing?

This is likely the case - if you're already investigating this, can you take a look at what port API is FF supporting and do they expose them under the chrome namespace or the browser namespace? - We might need to add the polyfill to messaging API in the next version. Would love some help on investigating this!

@kenkantzer-truss
Copy link
Author

ah @louisgv, this looks like a known problem:

Google Chrome uses chrome while Mozilla Firefox, the old Microsoft Edge and Safari also support the browser-neutral browser

It looks like Mozilla has a pretty extensive polyfill for going from browser API to chrome API: ...so it seems like the need would be to go from chrome.runtime to browser.runtime for Firefox/Edge support, and use Mozilla's polyfill to get chrome support.

There's of course this little gem from the Chromium bug report:

One key difference to note while adding this is that the WebExtensions spec is largely promise-based, while the chrome.* APIs are callback-based. Oh, and as a stop-gap solution, Mozilla has had a polyfill [2] out for a while to help people use the same extension code in Chrome and Firefox (and Edge) both.

Which means that places like sendMessage's callback need to be changed? I don't have the skill to switch things over to using the polyfill, but would be happy to test a build of @plasmohq/messaging & do some tweaking.

@louisgv
Copy link
Contributor

louisgv commented Feb 27, 2023

It looks like Mozilla has a pretty extensive polyfill for going from browser API to chrome API: ...so it seems like the need would be to go from chrome.runtime to browser.runtime for Firefox/Edge support, and use Mozilla's polyfill to get chrome support.

One issue with this polyfill is that it's more or less just a promisified module over browser instead of an actual polyfill. And it throws on API unavailable at import - which is nuts! - IMO Polyfill should not throw runtime errors on import. If API is unavailable, mock stuff out or have a fallback hatch, or throw on invocation.

The error it throws break a bunch of stuff in a manner that has no way to go around them lol

@kenkantzer-truss The new Relay API should decoupled from the chrome.runtime stuff so you can now walk around this issue. I've created a PR to switch over to the new promise API as well, which will hopefully fix the issue you are having with chrome runtime:

#462

@weltan
Copy link

weltan commented Mar 2, 2023

oo, thanks @louisgv - is this PR in @plasmohq/messaging 0.1.4 yet? happy to I give it a try!

@louisgv
Copy link
Contributor

louisgv commented Mar 2, 2023

@weltan yup, please try it out!

@louisgv louisgv closed this as completed Mar 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants