I would like to implement Google's Push Notification in a website and followed this tutorial by Google:

https://developers.google.com/web/ilt/pwa/introduction-to-push-notifications

I managed to display a Push Notification and the permission status in the Console but got stuck with the stage where the showNotification method is used to bring up a message.

My code goes as follows:

Notification.requestPermission(status => {
  console.log('Notification permission status:', status);
});

function displayNotification() {
  if (Notification.permission == 'granted') {
    navigator.serviceWorker.getRegistration().then(function(reg) {
      reg.showNotification('Hello world!');
    });
  }
}

I browsed the videos and labs to no avail. They simply use the code stated above or similar with with the optional array incorporated.

Please help me work out how calling the showNotification method can modify the Push Notification.

0 Answers