The getSubscription() method on PushManager retrieves an existing push subscription—or null if the user has not subscribed. Learn the MDN serviceWorker.ready pattern, updating subscribe/unsubscribe UI, syncing PushSubscription to your server, and async/await—with five examples and try-it labs.
01
Kind
Instance method
02
Returns
Promise
03
Value
PushSubscription
04
Or null
not subscribed
05
Call on
pushManager
06
Status
Baseline Mar 2023
Fundamentals
Introduction
Web push needs a PushSubscription—endpoint URL plus encryption keys—before your server can send messages. Users may subscribe once and return later. On each visit you need to know: is there already a subscription?
registration.pushManager.getSubscription() answers that. MDN: it returns a Promise resolving to a PushSubscription or null. Use it on page load to restore UI state and keep your backend in sync.
💡
Beginner tip
Wait for navigator.serviceWorker.ready before calling getSubscription()—you need an active service worker registration with a pushManager.
Concept
Understanding getSubscription()
An instance method on PushManager that reads the current subscription without creating a new one.
Parameters — none.
Returns — Promise<PushSubscription | null>.
PushSubscription — includes endpoint and keys via getKey().
null — no subscription exists for this registration.
vs subscribe() — subscribe() creates; getSubscription() only reads.
Secure context — HTTPS or localhost required.
Baseline Widely available on MDN (since March 2023).
Foundation
📝 Syntax
JavaScript
pushManager.getSubscription()
Return value
A Promise that resolves to a PushSubscription object, or null if no subscription exists.
Typical pattern (MDN)
JavaScript
navigator.serviceWorker.ready.then((registration) => {
registration.pushManager
.getSubscription()
.then((subscription) => {
if (!subscription) {
// Not subscribed — show enable UI
return;
}
// Subscribed — sync server, update UI
sendSubscriptionToServer(subscription);
});
});
The PushManager.getSubscription() method is Baseline Widely available on MDN (since March 2023). Requires a secure context. Logos use the shared browser-image-sprite.png sprite from this project.
✓ Baseline · Widely available
PushManager.getSubscription()
Retrieve existing PushSubscription or null in push-enabled browsers.
UniversalWidely available
Google ChromeFull support · Desktop & Mobile
Full support
Mozilla FirefoxFull support · Desktop & Mobile
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
getSubscription()Excellent
Bottom line: Call after serviceWorker.ready; handle null for users who have not subscribed.
Wrap Up
Conclusion
pushManager.getSubscription() returns a Promise with the current PushSubscription or null. Call it after serviceWorker.ready to restore UI and sync your server—without calling subscribe() again.
It retrieves an existing push subscription for this pushManager. It returns a Promise that resolves to a PushSubscription object, or null if the user has not subscribed.
No. MDN marks PushManager.getSubscription() as Baseline Widely available (since March 2023). It is not Deprecated, Experimental, or Non-standard.
No. MDN documents getSubscription() with no parameters. Call it on a PushManager instance: registration.pushManager.getSubscription().
When there is no existing push subscription for this service worker registration—typically before the user has granted notification permission and subscribed.
getSubscription() only reads the current subscription. subscribe() creates a new subscription (and may prompt the user). Use getSubscription() on page load to restore UI state.
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’s sample calls getSubscription() before enabling the push button—so the UI reflects whether the user already subscribed, without calling subscribe() on every page load.