firebase-js-sdk icon indicating copy to clipboard operation
firebase-js-sdk copied to clipboard

isSupported returns false positive

Open ptahchiev opened this issue 5 months ago • 10 comments

Operating System

iOS v 17.3

Browser Version

Safari

Firebase SDK Version

10.10.0

Firebase SDK Product:

Messaging

Describe your project's tooling

React app with webpack

Describe the problem

I'm trying to develop push notifications with FCM. Here's part of the code:

import { getMessaging, onMessage, getToken, isSupported } from "firebase/messaging";
....
try {
  if (isSupported) {
    console.log('is supported');
      // Retrieve Firebase Messaging object
      messaging = getMessaging(app);
  }
} catch (e) {
  console.error(e)
}

As you can see I'm using isSupported. However in the log I can see that is supported is printed and then an error is thrown: This browser does not support the APIs required to use the Firebase SDK. Screenshot from 2024-04-05 16-29-32

If I comment the snippet then no error is thrown and nothing is logged in the console.

Steps and code to reproduce issue

Just call isSupported on iOS and you will see it returns true

ptahchiev avatar Apr 05 '24 13:04 ptahchiev

Hi @ptahchiev, thanks for bringing this to our attention. I tried replicating, but I wasn't able to reproduce the error. If I can replicate the issue, I can have a better look into it. Please share a minimal, but complete sample of a project that I can run locally.

jbalidiong avatar Apr 08 '24 15:04 jbalidiong

Just checking to ensure that your code is correct.

Are you invoking if(isSupported()) or just checking if it's defined if(isSupported). Looks like the latter is in the test case above.

Thanks!

DellaBitta avatar Apr 08 '24 17:04 DellaBitta

Here's a reproducible site: https://ptahchiev.github.io/test-firebase/ with repository: https://github.com/ptahchiev/test-firebase/ and result: image

ptahchiev avatar Apr 09 '24 12:04 ptahchiev

Thanks for the minimal repro, @ptahchiev. I was able to replicate the behavior. Let me check what we can do for this issue or bring someone here that can provide more context about it. I’ll update this thread if I have any information to share.

jbalidiong avatar Apr 10 '24 12:04 jbalidiong

I'm not able to get an iOS emulator running at the moment to repro this, but I think the problem is that isSupported() is an async function, so you would have to do if (await isSupported()). In your sample code, the value of isSupported() isn't actually true, it's a promise, which is truthy, which always causes your if to pass. If you logged the value of isSupported() instead of the string "isSupported() is true", this would show up.

Can I ask what documentation guide or tutorial you used for adding isSupported()? I want to make sure we didn't make a mistake and we add await if needed.

hsubox76 avatar Apr 12 '24 18:04 hsubox76

Just dropping in to say I have same issue. I am using await isSupported(). And get same exact experience as OP. My only difference is I am using 10.11.0.

SteveKennedy avatar Apr 17 '24 22:04 SteveKennedy

Can you provide a repro like the original poster did?

hsubox76 avatar Apr 22 '24 20:04 hsubox76

Hey @ptahchiev. We need more information to resolve this issue but there hasn't been an update in 5 weekdays. I'm marking the issue as stale and if there are no new updates in the next 5 days I will close it automatically.

If you have more information that will help us get to the bottom of this, just add a comment!

google-oss-bot avatar Apr 29 '24 01:04 google-oss-bot

Is your manifest configured correctly with { "display": "standalone" } // or {"display": "fullscreen"}? The config appears to be an requirement according to https://firebase.blog/posts/2023/08/fcm-for-safari/

zwu52 avatar Apr 29 '24 18:04 zwu52

Hey @ptahchiev. We need more information to resolve this issue but there hasn't been an update in 5 weekdays. I'm marking the issue as stale and if there are no new updates in the next 5 days I will close it automatically.

If you have more information that will help us get to the bottom of this, just add a comment!

google-oss-bot avatar May 06 '24 01:05 google-oss-bot

Since there haven't been any recent updates here, I am going to close this issue.

@ptahchiev if you're still experiencing this problem and want to continue the discussion just leave a comment here and we are happy to re-open this.

google-oss-bot avatar May 13 '24 01:05 google-oss-bot