JavaScript PushManager getSubscription() Method

Beginner
⏱️ 11 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Baseline Widely available
Instance method

What You’ll Learn

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

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.

Understanding getSubscription()

An instance method on PushManager that reads the current subscription without creating a new one.

  • Parameters — none.
  • ReturnsPromise<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).

📝 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);
    });
});

⚡ Quick Reference

GoalCode / note
Get subscriptionawait reg.pushManager.getSubscription()
Not subscribed?subscription === null
After SW readynavigator.serviceWorker.ready
Read endpointsubscription.endpoint
Handle errors.catch() on the Promise
MDN statusBaseline Widely available (since March 2023)

🔍 At a Glance

Four facts to remember about getSubscription().

Async
Promise

Always await

Hit
PushSubscription

If subscribed

Miss
null

Not subscribed

Baseline
Mar 2023

Widely available

Examples Gallery

Examples follow MDN getSubscription(). Use View Output or Try It Yourself.

📚 Getting Started

Check subscription state on page load.

Example 1 — MDN: Check Subscription & Update UI

Official MDN pattern after serviceWorker.ready.

JavaScript
navigator.serviceWorker.ready.then((registration) => {
  registration.pushManager
    .getSubscription()
    .then((subscription) => {
      const pushButton = document.querySelector(".js-push-button");
      pushButton.disabled = false;

      if (!subscription) {
        // Not subscribed — show enable UI
        return;
      }

      sendSubscriptionToServer(subscription);
      pushButton.textContent = "Disable Push Messages";
    })
    .catch((err) => {
      console.error(`Error during getSubscription(): ${err}`);
    });
});
Try It Yourself

How It Works

Call on load to restore button state without prompting the user again.

Example 2 — Explicit null Check

MDN: resolves to null when no subscription exists.

JavaScript
const registration = await navigator.serviceWorker.ready;
const subscription = await registration.pushManager.getSubscription();

if (subscription === null) {
  console.log("User is not subscribed to push");
} else {
  console.log("User is subscribed");
}
Try It Yourself

How It Works

Always branch on null—do not assume a subscription exists.

📈 async/await & Server Sync

Modern syntax and backend handoff.

Example 3 — async/await Version

Same logic with cleaner async flow.

JavaScript
async function checkPushSubscription() {
  const registration = await navigator.serviceWorker.ready;
  const subscription = await registration.pushManager.getSubscription();
  return subscription !== null;
}

const isSubscribed = await checkPushSubscription();
console.log(isSubscribed); // false until user subscribes
Try It Yourself

How It Works

Wrap in try/catch for permission or service worker errors.

Example 4 — Read endpoint When Subscribed

Inspect the push URL your server will POST to.

JavaScript
const subscription = await registration.pushManager.getSubscription();

if (subscription) {
  console.log(subscription.endpoint);
  // e.g. "https://fcm.googleapis.com/fcm/send/…"
}
Try It Yourself

How It Works

Endpoint comes from the browser’s push service, not your origin.

Example 5 — Sync Subscription to Server

MDN: keep server in sync when a subscription already exists.

JavaScript
function sendSubscriptionToServer(subscription) {
  return fetch("/api/push-subscription", {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify(subscription),
  });
}

const sub = await registration.pushManager.getSubscription();
if (sub) {
  await sendSubscriptionToServer(sub);
}
Try It Yourself

How It Works

Re-post on each visit so the backend always has the latest subscription object.

🚀 Common Use Cases

  • On page load, show “Enable push” vs “Disable push” button text.
  • Re-sync PushSubscription to your backend on every visit.
  • Skip subscribe() if user is already subscribed.
  • Debug push setup by logging endpoint in DevTools.
  • Gate push features behind getSubscription() !== null.

🔧 How It Works

1

SW ready

Wait for navigator.serviceWorker.ready.

Setup
2

Call method

registration.pushManager.getSubscription().

Query
3

Promise resolves

PushSubscription or null.

Result
4

Update app

Sync server, toggle UI, or call subscribe() if null.

📝 Notes

Universal Browser Support

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.

Universal Widely available
Google Chrome Full support · Desktop & Mobile
Full support
Mozilla Firefox Full support · Desktop & Mobile
Full support
Apple Safari Full support · macOS & iOS
Full support
Microsoft Edge Full support · Chromium
Full support
Opera Full support · Modern versions
Full support
Internet Explorer No Push API / service workers
Not supported
getSubscription() Excellent

Bottom line: Call after serviceWorker.ready; handle null for users who have not subscribed.

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.

Continue with supportedContentEncodings, navigator.serviceWorker, PushEvent.data, or the JavaScript hub.

💡 Best Practices

✅ Do

  • Wait for navigator.serviceWorker.ready first
  • Handle null and show enable-push UI
  • Re-sync subscription to your server when non-null
  • Use .catch() or try/catch for errors
  • Call on every page load to keep UI accurate

❌ Don’t

  • Confuse getSubscription() with subscribe()
  • Assume a subscription exists without checking
  • Call before the service worker is ready
  • Expect it to work outside a secure context
  • Skip server sync when subscription is found

Key Takeaways

Knowledge Unlocked

Five things to remember about getSubscription()

Check existing push subscriptions safely.

5
Core concepts
🔄02

Promise

async

Returns
📦03

object

subscribed

Hit
04

null

not yet

Miss
🎯05

Baseline

since Mar 2023

Status

❓ Frequently Asked Questions

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.

Create push subscription

Learn subscribe()—enable push when the user clicks a button.

subscribe() →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

5 people found this page helpful