Prompt
web push notifications api
Latest observation
Nov 3, 2026
OpenAI APIWeb search: off
The Web Push Notifications API is usually built from a few related web platform features:
- Notification API — shows notifications in the browser
- Service Workers — receive push events in the background
- Push API — lets the browser receive push messages from a server
- Push Service — browser/vendor infrastructure that delivers the push
- VAPID — a way for your server to identify itself to push services
Typical flow
- User grants notification permission.
- Your app registers a service worker.
- Your app subscribes to push messages via the Push API.
- Subscription details are sent to your server.
- Your server sends a push message to the push service.
- The service worker receives the push event and shows a notification.
Basic example
1) Register a service worker
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('/sw.js');
}
2) Request notification permission
Notification.requestPermission().then(permission => {
console.log(permission); // "granted", "denied", or "default"
});
3) Subscribe to push
async function subscribeUser() {
const registration = await navigator.serviceWorker.ready;
const subscription = await registration.pushManager.subscribe({
userVisibleOnly: true,
applicationServerKey: 'YOUR_PUBLIC_VAPID_KEY'
});
await fetch('/subscribe', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(subscription)
});
}
4) Handle push events in the service worker
self.addEventListener('push', event => {
const data = event.data ? event.data.json() : {};
const title = data.title || 'New notification';
event.waitUntil(
self.registration.showNotification(title, {
body: data.body || 'You have a new message',
icon: '/icon.png'
})
);
});
Important notes
- Requires HTTPS (except localhost).
- Notifications can only be shown after user permission.
- In most browsers, push notifications require a service worker.
- You generally need a server to send push messages.
- Mobile/desktop support varies by browser and OS.
Browser support
Good support in:
- Chrome
- Edge
- Firefox
- Some support in Safari, but with platform-specific limitations
If you want, I can also provide:
- a full working demo,
- a Node.js backend example, or
- a React implementation.