Skip to content

API in Notifications

Web Push and PushManager.subscribe()

Published

Available in all core browsersW3C

registration.pushManager.subscribe() asks the browser’s push service for a PushSubscription whose endpoint your server can POST encrypted messages to; the browser can deliver each message to the service worker as a push event even when no page is open, and the worker typically shows a notification. Together with the Notifications API this is Web Push, the only standard way for a server to reach a PWA user who has closed the app.

Sequence diagram of Web Push across the web page, service worker, push service and application server: the page requests notification permission, calls pushManager.subscribe() with the VAPID public key, receives a PushSubscription and posts it to the server. The server sends a VAPID-signed, encrypted request to the endpoint, the push service delivers it, the browser fires the push event in the service worker, which calls showNotification(). A tap fires notificationclick, and pushsubscriptionchange triggers a resubscribe.
Web Push from subscription to notification: who talks to whom, and which event fires where.
registration.pushManager.subscribe(options)
registration.pushManager.getSubscription()
registration.pushManager.permissionState(options)
subscription.toJSON()
subscription.unsubscribe()

subscribe() resolves with a PushSubscription, or with the existing one when the registration is already subscribed with the same options. getSubscription() resolves with the current subscription or null. All three are available from a window and from the service worker’s own self.registration. Support starts with Chrome 42, Firefox 44, Edge 17, Safari 16 on macOS Ventura, Safari 16.4 on iOS for Home Screen web apps (BCD api.PushManager.subscribe). Firefox 72+ requires subscribe() to run inside a user gesture; Chromium requires applicationServerKey.

Parameter Type Meaning
options.userVisibleOnly boolean Promise that every push results in a visible notification. Chromium and WebKit reject false with NotAllowedError; WebKit also revokes a subscription whose push handler fails to show one (Meet Web Push, webkit.org). Firefox accepts false and applies a quota to silent pushes instead.
options.applicationServerKey BufferSource or base64url string Your VAPID public key, an uncompressed P-256 point of 65 bytes. The server signs each send with the matching private key (RFC 8292, ietf.org). Required in Chromium; a subscription without it in Firefox cannot be migrated to VAPID later without unsubscribing.

The returned PushSubscription serialises with toJSON() to { endpoint, expirationTime, keys: { p256dh, auth } }. endpoint is a capability URL on the browser vendor’s push service (web.dev’s example shows an https://fcm.googleapis.com/fcm/send/… URL for Chrome, and WebKit uses push.apple.com subdomains for Safari); it addresses the device’s subscription, so it is transmitted and stored like a credential. A subscription restricted by a VAPID key also requires a JWT signed with the matching private key (RFC 8292). p256dh and auth are the subscription’s public key and authentication secret; the application server uses them for RFC 8291 payload encryption, and the browser decrypts. expirationTime is null when the subscription has no expiry, as in web.dev’s example subscription.

Exception When
NotAllowedError DOMException Notification permission is "denied", or the user dismissed the prompt that subscribe() triggered; userVisibleOnly is false in Chromium or WebKit; the call is outside a user gesture in Firefox 72+; the service worker’s scope is not a secure context.
InvalidStateError DOMException The registration has no active worker, or a subscription already exists with a different applicationServerKey. Unsubscribe before changing keys.
InvalidAccessError DOMException applicationServerKey is not a valid P-256 public key (wrong length or not an uncompressed point).
InvalidCharacterError DOMException The base64url string form of applicationServerKey fails to decode.
AbortError DOMException The push service could not create the subscription, or the subscription had an error. Retry later.

Server-side failures are HTTP statuses from the push service, not exceptions: 404 and 410 mean the subscription is gone and must be deleted; 413 means the push service judged the request body too large (RFC 8030 says a service must not return 413 for a body of 4096 bytes or less); 429 means the service is rate-limiting the application server.

Subscribe from the page and receive messages in the service worker. Check for an existing subscription first.

Subscribing from a click and posting the subscription to the server

Section titled “Subscribing from a click and posting the subscription to the server”

The permission request and the subscription both start in the click handler below. The key arrives from the server as a base64url string, which the specification allows subscribe() to take directly; the urlBase64ToUint8Array() conversion seen in older tutorials is only needed for engines that predate that change.

button.addEventListener('click', async () => {
const registration = await navigator.serviceWorker.ready;
const permission = await Notification.requestPermission();
if (permission !== 'granted') return;
const { publicKey } = await (await fetch('/api/push/key')).json();
const subscription = await registration.pushManager.subscribe({
userVisibleOnly: true,
applicationServerKey: publicKey,
});
await fetch('/api/push/subscriptions', {
method: 'POST',
headers: { 'content-type': 'application/json' },
body: JSON.stringify(subscription.toJSON()),
});
});

Store the subscription keyed by user and device, and delete it when a send returns 404 or 410; a stale endpoint that keeps being pushed to is the most common cause of silent delivery failure.

Receiving the message and resubscribing when the endpoint changes

Section titled “Receiving the message and resubscribing when the endpoint changes”

The push handler should show a notification in response to each push; Safari requires one. pushsubscriptionchange fires when a subscription is refreshed, revoked, or lost outside the page’s control; the worker below resubscribes with the old subscription’s key when oldSubscription is available and tells the server.

self.addEventListener('push', (event) => {
const data = event.data?.json() ?? {};
event.waitUntil(
self.registration.showNotification(data.title ?? 'Update', {
body: data.body ?? '',
data: { url: data.url ?? '/' },
})
);
});
self.addEventListener('pushsubscriptionchange', (event) => {
event.waitUntil((async () => {
const key = event.oldSubscription?.options.applicationServerKey;
const subscription = await self.registration.pushManager.subscribe({ userVisibleOnly: true, applicationServerKey: key });
await fetch('/api/push/subscriptions', { method: 'POST', body: JSON.stringify(subscription.toJSON()) });
})());
});

pushsubscriptionchange fires in Firefox 44 (without oldSubscription, bug 1497429), Safari 16, and Chrome 138 (BCD api.ServiceWorkerGlobalScope.pushsubscriptionchange_event); before Chrome 138 a server learns of a lost subscription from the 410 it receives, or when the page next reports its subscription.

Detecting support and reusing an existing subscription

Section titled “Detecting support and reusing an existing subscription”

Check for PushManager on the registration, then use getSubscription() to read the current subscription without changing it. The fallback is polling or in-app messages.

async function currentSubscription() {
if (!('serviceWorker' in navigator) || !('PushManager' in window)) {
return null; // no push: poll for updates while the app is open
}
const registration = await navigator.serviceWorker.getRegistration();
if (!registration?.active) return null;
return registration.pushManager.getSubscription(); // existing subscription or null
}

A null here with permission "granted" means the user has not subscribed yet, which is the moment to show the enable button from the first example.

The companion demo at /demo/#push calls Notification.requestPermission() and then pushManager.subscribe() with a VAPID public key generated for the demo, and prints the resulting PushSubscription JSON. No server sends messages in this demo, so you can inspect the permission flow and subscription shape without receiving a push.

Specifications

SpecificationStatus
Web PushW3C
  • Legend
  • Yes
  • Partial
  • Flag
  • No
  • Unknown
Browser / PlatformSupportVersionsConfidenceSourceNotes
Chrome (Desktop)#Yes42highsource1
Chrome (Android)#Yes42highsource23
Edge (Desktop)#Yes17highsource4
Firefox (Desktop)#Yes44highsource5
Firefox (Android)#Yes48highsource6
Safari (macOS)#Yes16highsource7
Safari (iOS)#Yes16.4highsource8
Samsung Internet#Yes4.0highsource910
WebView (Android)#No—highsource11
Safari (iOS) · Declarative Web Push#Yes18.4mediumsource121314
  1. The `options` parameter with a `applicationServerKey` value is required.
  2. The `options` parameter with a `applicationServerKey` value is required.
  3. Derived by browser-compat-data mirroring from Chrome.
  4. The `options` parameter with a `applicationServerKey` value is required.
  5. From Firefox 72 onwards, can only be called in response to a user gesture such as a `click` event.
  6. From Firefox Android 79 onwards, can only be called in response to a user gesture such as a `click` event.
  7. Notifications are supported on macOS Ventura and later.
  8. Notifications are supported in web apps saved to the home screen.
  9. The `options` parameter with a `applicationServerKey` value is required.
  10. Derived by browser-compat-data mirroring from Chrome Android.
  11. No WebView Android support is recorded in browser-compat-data.
  12. WebKit's Safari 18.4 post: "Declarative Web Push is now available on iOS and iPadOS 18.4 for web apps added to the Home Screen." It describes Declarative Web Push as push notifications that can display without requiring a service worker.
  13. browser-compat-data has no Declarative Web Push entry. Its nearest key, `api.Window.pushManager`, records Safari on iOS 18.4 and is marked experimental.
  14. OpenPWA device test, 2026-10-20, iPhone 16 Pro, iOS 18.6.2 (22G100): `window.pushManager` is also exposed in a plain Safari tab; in a Home Screen app whose service worker is scoped to a subpath, `window.pushManager.getSubscription()` returned `null` while the worker's registration held a subscription, consistent with WebKit's statement that only a root-scoped worker shares the window's subscription.

Ecosystem & commercial policy

EntityTypeContextStatusSponsoredNotes
Apple Push (APNs)#delivery_policyiOSPartialNoiOS Web Push requires the user to add the app to the Home Screen first.

Source data: /compatibility/web-push.json · Global usage: 96 % (StatCounter 2026-09, CC BY-SA 4.0)

Source: spec · MDN · Last verified 2026-10-20 · Confidence: medium (computed from sources)

Cite this table

Web Push compatibility data — OpenPWA · Verified 2026-10-20 · CC BY 4.0 · JSON

When reusing compatibility data, keep the attribution, identify your changes and check each row’s original source. This citation excludes market-share and reach figures, which use CC BY-SA 4.0.