PushManager.subscribe(options) subscribes to a push service and returns a Promise that resolves to a PushSubscription with an endpoint URL and encryption keys (MDN). If the service worker already has a subscription, that one is returned; otherwise a new one is created.
Pass the required arguments shown below. Check return values and browser support before you rely on the result.
Syntax
Call pushManager.subscribe. Start with this line.
JavaScript
pushManager.subscribe(options?)
Call
What it does
pushManager.subscribe(options?)
Primary signature.
pushManager.subscribe(...)
Call with the arguments your case needs.
Built into the browser. Call subscribe(...) on a PushManager — no import required.
Library declarations
JavaScript
pushManager.subscribe(options?)
Parameters
Parameter
Description
Service worker
Required. Host for pushManager
userVisibleOnly
Required. Must be true or the Promise rejects
Return Value
Return Value
Description
*
Promise<PushSubscription>
JavaScript Examples
Example 1 — MDN subscribe() Pattern
Subscribe after serviceWorker.ready with VAPID options.
Create the subscription. Same subscribe() call as before.
Serialize it.JSON.stringify(subscription) includes endpoint and keys.
POST to your API. The server stores it for later Web Push sends.
Confirm. Log success so the UI can show “Push Enabled”.
Compatibility
Browser Support
PushManager.subscribe() is Baseline Widely available (MDN, since March 2023). It requires a secure context and a service worker.
✓ Baseline · Widely available
PushManager.subscribe()
Create a PushSubscription with endpoint and encryption keys for web push.
WideModern browser support
Google ChromeSupported · userVisibleOnly required
Full support
Mozilla FirefoxSupported · Desktop & Android
Full support
Apple SafariSupported · modern Safari / iOS
Full support
Microsoft EdgeSupported · userVisibleOnly required
Full support
OperaFollow Chromium
Full support
Internet ExplorerNo Push API
Not supported
subscribe()Widely available
Bottom line: Supported in current Chrome, Firefox, Safari, and Edge. Always use HTTPS (or localhost), set userVisibleOnly: true for Chromium, and call from a user gesture.
Frequently Asked Questions
It subscribes to a push service and returns a Promise that resolves to a PushSubscription with an endpoint URL and encryption keys. A new subscription is created if the current service worker has none.
No. MDN marks PushManager.subscribe() as Baseline Widely available (since March 2023). It is not Deprecated, Experimental, or Non-standard.
An optional object with userVisibleOnly (boolean; Chrome and Edge require true) and applicationServerKey (your VAPID public key as a Base64 string or ArrayBuffer/Uint8Array).
After navigator.serviceWorker.ready, usually from a user gesture such as a button click. Browsers may block subscribe prompts that are not user-initiated.
subscribe() creates (or returns) a push subscription and may prompt the user. getSubscription() only reads the current subscription without creating one.
Yes. The Push API is a secure-context feature — use HTTPS or localhost. It is also available in Web Workers where supported.