Skip to content

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

Open
@pablor21

Description

@pablor21

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);
  });

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions