Can't get notification payload from firebase-sw on Ionic PWA

I’ve searched a lot for this problem that I’m stuck on for a week. I have an Ionic PWA project that receive some notifications from firebase, I can receive the notifications with no problem and can get the payload on foreground (app is open), but I cant get the payload when the app is closed and I don’t figure out what is goning on, so I came here to ask the masters to help me.

messaging.setBackgroundMessageHandler(function(payload) {
    var notificationTitle = 'Teste';
    var notificationOptions = {
      body: 'Background Message body.',
      tag: 'campanhas',
      icon: ''

   return self.registration.showNotification(notificationTitle,

self.addEventListener('notificationclick', function(event) {

     type: "window"
   }).then(function(clientList) {
     for (var i = 0; i < clientList.length; i++) {
       var client = clientList[i];
       if (client.url == '/' && 'focus' in client)
       return client.focus();
     if (clients.openWindow)
      return clients.openWindow('/');

and on my provider for the notifications, I use this code:

public receiveMessage() {
  this.messaging.onMessage((payload) => {

I call this provider on my tabs-page:


So, can anyone help me to get the payload when the PWA is closed?

I’m having the same problem! I tried @ionic-native/fcm and then @ionic-native/firebase-messaging. Both seem to promise this functionality but I haven’t been able to get either to work.

I get the push notification just fine but the callback here never fires.

this.firebaseMessaging.onBackgroundMessage().subscribe(message => {
               console.log(‘got message in background’,message);

I’d expect that this would save the data from the notification but no. I can find examples for the cordova onBackgroundMessage but not the ionic wrapper. I can’t imagine there’s a function for onBackgroundMessage but no ability to receive and process background messages.

Have you got solution.I stucked here.Please send me solution if yo got a solution,Thanks

You’ve to use service workers!

Service workers only works for PWA apps not on android or ios platform.I need for ios and android platform.

You’re sort of in a strange thread, then.

1 Like

That is indeed the topic of a different thread. There’s a number of little things that can go wrong with Firebase push notifications for Android and iOS. You just have to go through each flow, check that each step is working, and try to find a specific error message. The big one is to make sure you’re getting a token from the client. Once you know you have that, you can send a test message. If that fails you’ll have have more info to refine you’re trouble-shooting.