This website shows how to make and handle persistent notifications.

It registers a service worker, whose job is to handle notifications. When the "Notify me!" button is clicked, the website does the following:

  1. Checks whether the website has permission to show notifications, asking for permission if necessary.
  2. If permission is granted, starts a one-second timer.
  3. When the timer expires, gets the service worker registration, waiting for it to become active if necessary.
  4. Calls registration.showNotification(), passing in two actions.

The notification presents the actions to the user. If the user clicks the notification, then the browser starts the service worker, if it is not already running, and dispatches the notificationclick event. If the user selected an action, then the event object includes the selected action.

The service worker's notificationclick handler checks the value of the event's action, and responds by opening the appropriate web page.