FCM: cannot push notification

I am using the recently released FCM messaging service for push notifications on chrome. When my application is in the background, I get a notification, but nothing happens when I click the notification. How do I specify a URL to open when a user clicks a notification? (I understand how this is done using the concept of a pure service worker using the notificationclick event, I want to know how to do this using FCM messaging .)

messaging.setBackgroundMessageHandler(function(payload) {
  var data = payload || {};
  var shinyData = decoder.run(data);

  console.log('[firebase-messaging-sw.js] Received background message ', shinyData);

  return self.registration.showNotification(shinyData.title, {
    body: shinyData.body,
    icon: shinyData.icon
  })
});

What am I missing here?

+4
source share
2

click_action showNotification.

, notificationclick.

:

self.addEventListener('notificationclick', function(event) {
  event.notification.close();
  event.waitUntil(self.clients.openWindow(YOUR_URL_HERE));
});
+5

.

Firebase - API -Push.

notification: { click_action: 'https://...' } . , notificationclick ( ).

self.addEventListener('notificationclick', function(event) {
  event.notification.close();

  ... Do your stuff here.
});

notificationclose:

self.addEventListener('notificationclose', function(event) {
  ... Do your stuff here.
});
+2

Source: https://habr.com/ru/post/1658603/


All Articles