IOS pwa shows notification even when the app is in the foreground
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);
});
Any updates? I'm facing the same issue.
@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?