JavaScript PushManager

Beginner
8 min read
Updated: Nov 2026
3 examples
Push subscribe

Definition and Usage

PushManager is the interface on a service worker registration that creates and reads push subscriptions: registration.pushManager.

Call subscribe({ userVisibleOnly: true, applicationServerKey }) after the user grants notification permission. Later use getSubscription() to see if a subscription already exists, and unsubscribe() on the subscription object to stop.

This page teaches what PushManager is. Method and property guides live under this section.

Needs a service worker registration.

Obtain const reg = await navigator.serviceWorker.ready, then use reg.pushManager.

JavaScript Syntax

Subscribe from the page:

JavaScript
const reg = await navigator.serviceWorker.ready;
const sub = await reg.pushManager.subscribe({
  userVisibleOnly: true,
  applicationServerKey: vapidKey
});
console.log(sub.endpoint);

Core Ideas

Ideas every PushManager tutorial builds on:

IdeaExampleRemember
Entryregistration.pushManagerFrom the SW registration
subscribepushManager.subscribe(...)Creates a PushSubscription
getSubscriptionpushManager.getSubscription()Existing sub or null
PermissionNotification.permissionMust be granted
VAPID keyapplicationServerKeyIdentifies your server
userVisibleOnlytrueRequired in browsers today

JavaScript Examples

Three short programs that show how PushManager works.

Example 1 — Check for an existing subscription

getSubscription resolves to a PushSubscription or null.

JavaScript
const reg = await navigator.serviceWorker.ready;
const sub = await reg.pushManager.getSubscription();
console.log(sub === null || typeof sub.endpoint === "string");

How It Works

  1. serviceWorker.ready waits for an active worker.
  2. getSubscription() reads any saved subscription.
  3. null means the user is not subscribed yet.

Example 2 — Check notification permission

Subscribe only after permission is granted.

JavaScript
console.log(Notification.permission);

How It Works

  1. Notification.permission is granted, denied, or default.
  2. Ask with Notification.requestPermission() when default.
  3. Do not call subscribe when permission is denied.

Example 3 — Feature-detect PushManager

Not every browser context supports push.

JavaScript
console.log("PushManager" in window);

How It Works

  1. "PushManager" in window is a quick check.
  2. Also ensure a service worker can register.
  3. Provide a UI fallback when unsupported.

Next: PushManager Guides

Continue with getSubscription, subscribe, and related properties.

Look upWhy
getSubscription()Read the current subscription
subscribe()Create a new subscription
permissionState()Push permission helper
PushEventHandle messages in the worker

Full lists: getSubscription().

Frequently Asked Questions

PushManager is the API on a service worker registration used to subscribe the browser to Web Push and to read the current subscription.
Register a service worker, await navigator.serviceWorker.ready, then use registration.pushManager.
It is your server’s VAPID public key so push services can authenticate your application when sending messages.
Browsers currently require true so push messages lead to a user-visible notification rather than silent background work alone.
Open getSubscription() and subscribe(), then PushEvent for handling messages.

Open getSubscription()

Then learn subscribe() and wire PushEvent in the service worker.

getSubscription() →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

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.

12 people found this page helpful