Push Notifications

The Push API reaches users even when your site is closed. The page gets a subscription (an endpoint on the browser vendor's push service plus keys) from its service worker registration. Your server signs with a VAPID key pair and POSTs an encrypted payload to that endpoint; the browser wakes the service worker, which must show a notification (SW Notifications). Push is Baseline Widely available (since September 2025); on iOS 16.4+ only Home Screen web apps get it. It needs user permission, so it was not run headless.

Subscribing, receiving and sending a push messageJavaScript
// page.js, in a click handler
const reg = await navigator.serviceWorker.register('/sw.js');
const sub = await reg.pushManager.subscribe({ userVisibleOnly: true, applicationServerKey: KEY });
await fetch('/subscribe', { method: 'POST', body: JSON.stringify(sub) });
// sw.js
self.onpush = (e) => e.waitUntil(registration.showNotification('Shipped', { body: e.data.text() }));
// server.js: npm install web-push; keys from npx web-push generate-vapid-keys
webpush.setVapidDetails('mailto:ops@example.com', KEY, PRIVATE_KEY);
await webpush.sendNotification(savedSub, 'Your parcel is on its way');

Delete a stored subscription when the push service answers 404 or 410.