https://meta.discourse.org/push-service-worker.js
✓ Published0🌍 Public
NN0taN3rd
Last edited May 26, 2017
Created on May 26, 2017
This example demonstrates how to handle push notifications in a service worker, replacing any existing notification with the same tag before displaying a new one, and managing notification clicks by focusing or navigating to the target URL. The code uses the Service Worker API, including `self.registration.showNotification`, `getNotifications`, `clients.matchAll`, and the `push` and `notificationclick` events. It reads payload data from the push event via `event.data.json()` and closes stale notifications before showing the new one.
AI-generated description