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

IOS pwa shows notification even when the app is in the foreground

Open pablor21 opened this issue 1 year ago • 11 comments

Operating System

IOS 17.2.1

Browser Version

Safari/10.7.2

Firebase SDK Version

10.7.2

Firebase SDK Product:

Messaging

Describe your project's tooling

Vue, Vite

Describe the problem

I'm trying to receive push messages on Iphone pwa. The notifications are coming just fine, the problem is that the notification is showing even if the app is in the foreground.

On desktop (mac/windows) and android it's working fine, but on IOS the notification always shows up regardless if the app is open or not.

Steps and code to reproduce issue

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

const firebaseConfig = {} // my config

firebase.initializeApp(firebaseConfig)
const messaging = firebase.messaging()


// If you would like to customize notifications that are received in the
// background (Web app is closed or not in browser focus) then you should
// implement this optional method.
// Keep in mind that FCM will still show notification messages automatically 
// and you should use data messages for custom notifications.
// For more info see: 
// https://firebase.google.com/docs/cloud-messaging/concept-options
messaging.onBackgroundMessage(function(payload) {
    console.log('[firebase-messaging-sw.js] Received background message ', payload);
    // Customize notification here
    const notificationTitle = 'Background Message Title';
    const notificationOptions = {
      body: 'Background Message body.',
      icon: '/img/logo.svg'
    };
  
    self.registration.showNotification(notificationTitle,
      notificationOptions);
  });

pablor21 avatar Feb 01 '24 23:02 pablor21

Any updates? I'm facing the same issue.

juyeongnoh avatar Apr 20 '24 12:04 juyeongnoh

@pablor21 Thanks for reporting this! Unfortunately, I haven't been able to reproduce it.

I have a PWA set up, and onBackgroundMessage running in a firebase-messaging-sw.js only gets triggered when the app is running in the background.

Could you share any additional information that may help me reproduce the issue?

dlarocque avatar Aug 16 '24 18:08 dlarocque