Home JavaScript PushManager JavaScript PushManager Definition
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.
Syntax
JavaScript Syntax Subscribe from the page:
const reg = await navigator.serviceWorker.ready;
const sub = await reg.pushManager.subscribe({
userVisibleOnly: true,
applicationServerKey: vapidKey
});
console.log(sub.endpoint); Reference
Core Ideas Ideas every PushManager tutorial builds on:
Idea Example Remember Entry registration.pushManagerFrom the SW registration subscribe pushManager.subscribe(...)Creates a PushSubscription getSubscription pushManager.getSubscription()Existing sub or null Permission Notification.permissionMust be granted VAPID key applicationServerKeyIdentifies your server userVisibleOnly trueRequired in browsers today
Code
JavaScript Examples Three short programs that show how PushManager works.
1. getSubscription 2. permission 3. support Example 1 — Check for an existing subscription getSubscription resolves to a PushSubscription or null.
const reg = await navigator.serviceWorker.ready;
const sub = await reg.pushManager.getSubscription();
console.log(sub === null || typeof sub.endpoint === "string"); How It Works serviceWorker.ready waits for an active worker.getSubscription() reads any saved subscription.null means the user is not subscribed yet. Example 2 — Check notification permission Subscribe only after permission is granted.
console.log(Notification.permission); How It Works Notification.permission is granted, denied, or default.Ask with Notification.requestPermission() when default. Do not call subscribe when permission is denied. Example 3 — Feature-detect PushManager Not every browser context supports push.
console.log("PushManager" in window); How It Works "PushManager" in window is a quick check.Also ensure a service worker can register. Provide a UI fallback when unsupported. Continue
Next: PushManager Guides Continue with getSubscription, subscribe, and related properties.
Look up Why getSubscription() Read the current subscription subscribe()Create a new subscription permissionState()Push permission helper PushEvent Handle messages in the worker
Full lists: getSubscription() .
Frequently Asked Questions What is PushManager? PushManager is the API on a service worker registration used to subscribe the browser to Web Push and to read the current subscription.
How do I get a PushManager? Register a service worker, await navigator.serviceWorker.ready, then use registration.pushManager.
What is applicationServerKey? It is your server’s VAPID public key so push services can authenticate your application when sending messages.
Why is userVisibleOnly required? Browsers currently require true so push messages lead to a user-visible notification rather than silent background work alone.
Where should I go next? 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.
About the author Developer, cloud engineer, and technical writer
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
Helpful Share Copy link Suggestion