JavaScript PushManager getSubscription() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Method

Definition

PushManager.getSubscription() retrieves an existing push subscription. Per MDN, it returns a Promise that resolves to a PushSubscription, or null if none exists. It does not prompt the user or create a subscription.

Pass the required arguments shown below. Check return values and browser support before you rely on the result.

Syntax

Call pushManager.getSubscription. Start with this line.

JavaScript
pushManager.getSubscription()
CallWhat it does
pushManager.getSubscription()Primary signature.
pushManager.getSubscription(...)Call with the arguments your case needs.

Built into the browser. Call getSubscription(...) on a PushManager — no import required.

Library declarations
JavaScript
pushManager.getSubscription()

Parameters

ParameterDescription
Secure contextRequired. HTTPS or localhost
Service worker registrationRequired. Provides pushManager

Return Value

Return ValueDescription
*Promise<PushSubscription | null>

JavaScript Examples

Example 1 — Check Subscription & Update UI

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 — keep Enable UI
        return;
      }

      // Keep server in sync + show Disable UI
      sendSubscriptionToServer(subscription);
      pushButton.textContent = "Disable Push Messages";
    })
    .catch((err) => {
      console.error(`Error during getSubscription(): ${err}`);
    });
});
Try It Yourself

How It Works

  1. Wait for ready. You need a live service worker registration.
  2. Call getSubscription. No parameters; returns a Promise.
  3. Branch on null. First-time users usually have no subscription.
  4. Restore UI. If subscribed, sync to the server and flip the button text.

Example 2 — Explicit null Check

Same idea with async/await.

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 the user subscribes
Try It Yourself

How It Works

  1. Await ready. Get the active registration.
  2. Await getSubscription. Resolves to an object or null.
  3. Convert to boolean. Handy for UI toggles and guards.
  4. No prompt. This never asks for notification permission by itself.

Example 3 — Read endpoint When Subscribed

Inspect the push service URL your backend will use.

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

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

How It Works

  1. Get the subscription. Same read-only call as before.
  2. Guard with if. Only read properties when the object exists.
  3. Log endpoint. That URL belongs to the browser push service.
  4. Handle null. Most demos print the “no endpoint” message first.

Browser & Runtime Support

PushManager.getSubscription() is marked Baseline Widely available on MDN (since March 2023). It is not Deprecated, Experimental, or Non-standard. Requires a secure context.

✓ Baseline · Widely available

PushManager.getSubscription()

Retrieve an existing PushSubscription or null. Supported in modern Chrome, Firefox, Safari, and Edge. Available since March 2023 per MDN Baseline.

96% Widely available
Google Chrome Supported · Desktop & Mobile
Full support
Mozilla Firefox Supported · Desktop & Mobile
Full support
Apple Safari Supported · macOS & iOS
Full support
Microsoft Edge Supported · Chromium
Full support
Internet Explorer No native support · Use a polyfill
Polyfill
Opera Supported · Modern versions
Full support
Samsung Internet Supported · Android
Full support
Bun Supported · JavaScript runtime
Supported
Deno Supported · JavaScript runtime
Supported
Node.js Supported · Server runtime
Supported
Android WebView Supported · Modern WebView
Full support
getSubscription() Excellent

Bottom line: Safe for modern browsers with service workers. Always branch on null, and use HTTPS or localhost.

Frequently Asked Questions

It retrieves an existing push subscription for this PushManager. It returns a Promise that resolves to a PushSubscription, or null if none exists.
No. MDN marks PushManager.getSubscription() as Baseline Widely available (since March 2023). It is not Deprecated, Experimental, or Non-standard.
No. Call it with empty parentheses on a PushManager instance: registration.pushManager.getSubscription().
When there is no existing push subscription for that service worker registration—usually before the user has subscribed.
getSubscription() only reads the current subscription and does not prompt. subscribe() creates a subscription and may ask for permission.
On registration.pushManager after navigator.serviceWorker.ready, in a secure context (HTTPS or localhost). MDN also notes it is available in Web Workers.

Next: subscribe()

Learn how to create a push subscription when the user opts in.

subscribe() tutorial →

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.

9 people found this page helpful