This website shows how to make and handle non-persistent notifications.

When we click the "Notify me!" button, 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, creates a non-persistent notification using the Notification() constructor.
  4. Adds event handlers to the main events dispatched on the Notification interface.

When the notification is shown, the user clicks it, or the user closes it, the corresponding event handler runs and logs the event.