The subscribe() method on PushManager creates a push subscription and returns a PushSubscription with endpoint and encryption keys. Learn the MDN serviceWorker.ready pattern, userVisibleOnly and VAPID applicationServerKey, user-gesture best practices, and syncing to your server—with five examples and try-it labs.
01
Kind
Instance method
02
Returns
Promise
03
Value
PushSubscription
04
Options
VAPID key
05
Gesture
button click
06
Status
Baseline Mar 2023
Fundamentals
Introduction
Web push lets your server send messages to users even when your PWA is closed. To enable that, the browser needs a PushSubscription—an endpoint URL plus encryption keys your server uses to deliver encrypted payloads.
pushManager.subscribe() requests that subscription from the push service. MDN marks it Baseline Widely available (since March 2023). It may prompt the user for notification permission and should be called after navigator.serviceWorker.ready, ideally from a button click.
💡
subscribe() vs getSubscription()
Call getSubscription() on page load to check for an existing subscription. Call subscribe() when the user clicks “Enable Push”—it creates a subscription if none exists.
Concept
Understanding subscribe()
An instance method on PushManager that subscribes to a push service and returns subscription details.
Parameters — optional options object.
userVisibleOnly — must be true in Chrome and Edge.
applicationServerKey — VAPID public key (Uint8Array or base64).
Returns — Promise<PushSubscription>.
Creates or reuses — new subscription if none exists for this SW.
User gesture — call from button click per MDN best practice.
Secure context — HTTPS or localhost required.
Available in Web Workers per MDN.
Foundation
📝 Syntax
JavaScript
pushManager.subscribe(options)
Return value
A Promise resolving to a PushSubscription object with endpoint and key material for your push server.
The PushManager.subscribe() method is Baseline Widely available on MDN (since March 2023). Requires a secure context and VAPID key in Chromium browsers. Logos use the shared browser-image-sprite.png sprite from this project.
✓ Baseline · Widely available
PushManager.subscribe()
Create PushSubscription with endpoint and keys in modern browsers.
UniversalWidely available
Google ChromeFull support · VAPID required
Full support
Mozilla FirefoxFull support · User gesture required
Full support
Apple SafariFull support · macOS & iOS
Full support
Microsoft EdgeFull support · Chromium
Full support
OperaFull support · Modern versions
Full support
Internet ExplorerNo Push API / service workers
Not supported
subscribe()Excellent
Bottom line: Call after serviceWorker.ready from a user gesture with userVisibleOnly: true and VAPID key.
Wrap Up
Conclusion
pushManager.subscribe() is the modern way to create a push subscription. Call it after serviceWorker.ready from a user gesture, pass userVisibleOnly: true and your VAPID key, then send the PushSubscription to your server.
It subscribes to a push service and returns a Promise that resolves to a PushSubscription object with endpoint URL and encryption keys. A new subscription is created if none exists for the current service worker.
No. MDN marks PushManager.subscribe() as Baseline Widely available (since March 2023). It is not Deprecated, Experimental, or Non-standard.
An optional object with userVisibleOnly (boolean, required true in Chrome/Edge) and applicationServerKey (VAPID public key as Uint8Array or base64 string).
After navigator.serviceWorker.ready, typically in response to a user gesture (button click). Browsers may block subscribe prompts not triggered by user interaction.
subscribe() creates or returns a push subscription and may prompt the user. getSubscription() only reads the current subscription without creating one.
On registration.pushManager after navigator.serviceWorker.ready, in a secure context (HTTPS or localhost). Also available in Web Workers per MDN.
Did you know?
MDN notes that subscribe() returns an existing subscription if the service worker already has one—but checking with getSubscription() first still helps you control UI and avoid unnecessary permission prompts.