Engaging users when the tab is closed
The Push API lets a server send messages to a service worker even when the web app is not open. Combined with the Notifications API, it powers re engagement like chat alerts.
- A user must grant notification permission first
- The browser provides a push subscription with an endpoint and keys
- The server sends an encrypted message to the push service endpoint
- The service worker wakes on a push event and shows a notification
VAPID and identity
Servers authenticate to the push service using VAPID keys, a public and private pair. The public key is passed when subscribing so the push service can verify the sender.
The end to end flow
The subscription endpoint is unique per user per browser. Your server stores it, then sends payloads to it. The push service relays the message, waking the worker which calls showNotification.
Key idea
The Push API delivers server messages to a sleeping service worker through a push service, authenticated by VAPID keys, which then displays a notification.