firebase / firebase-js-sdk

Firebase Javascript SDK
https://firebase.google.com/docs/web/setup
Other
4.84k stars 889 forks source link

Cloud Messaging doesn't work in Firefox for Android #5165

Open danieloliveira117 opened 3 years ago

danieloliveira117 commented 3 years ago

Describe your environment

Describe the problem

In Firefox for Android when trying to get the messaging token it crashes with the following error: image

The same code is functional in Chrome (Android, Windows, Ubuntu), Firefox (Windows, Ubuntu) and Edge (Windows).

Steps to reproduce:

  1. Attempt to get messaging token in Firefox for Android.

Relevant Code:

Main app:

const firebaseApp = firebase.initializeApp({...});
const messaging = firebaseApp.messaging();
const currentToken = await messaging.getToken({
    vapidKey: '...',
});

firebase-messaging-sw.js:

importScripts('https://www.gstatic.com/firebasejs/8.6.1/firebase-app.js');
importScripts('https://www.gstatic.com/firebasejs/8.6.1/firebase-messaging.js');

firebase.initializeApp({...});

const messaging = firebase.messaging();
messaging.onBackgroundMessage((payload) => {
    console.log(
        '[firebase-messaging-sw.js] Received background message ',
        payload
    );
});
google-oss-bot commented 3 years ago

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

looptheloop88 commented 3 years ago

Hi @danieloliveira117, thanks for the report. I was able to replicate the issue. I noticed that the dialog box or prompt asking for notification permission is missing in the Mozilla Firefox browser app on an Android device.

I'm not really sure if this is a bug in the JS FCM SDK or in the Mozilla Firefox browser app. Let me check and update this thread if I have any information to share.

danieloliveira117 commented 3 years ago

@looptheloop88 I forgot to add in the code above, but in Firefox it only shows the permission request if it originates from a user interaction (eg: click)

Quoting MDN:

From Firefox 72 onwards, can only be called in response to a user gesture such as a click event.

looptheloop88 commented 3 years ago

Thanks for the additional information @danieloliveira117. I tried pasting the URL of my test app in the Notes app and clicked it, but the only prompt I got was the "Open with" available browsers.

looptheloop88 commented 3 years ago

Probably related to this Stack Overflow post.

danieloliveira117 commented 3 years ago

@looptheloop88 I'm not 100% if its the same issue, but by doing a factory reset of the app. I was able to get the token/receive notifications correctly.

jahooma commented 3 years ago

This is affecting us. If the user sets Firefox set as their default browser, our PWA web app (actually a TWA android app) fails to receive any browser push notifications.