PushSubscription

This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

The PushSubscription interface of the Push API provides a subcription's URL endpoint and allows unsubscription from a push service.

An instance of this interface can be serialized.

Properties

PushSubscription.endpoint Read only
A USVString containing the endpoint associated with the push subscription.
PushSubscription.expirationTime Read only
A DOMHighResTimeStamp of the subscription expiration time associated with the push subscription, if there is one, or null otherwise.
PushSubscription.options Read only
An object containing the options used to create the subscription.
PushSubscription.subscriptionId Read only
A DOMString containing the subscription ID associated with the push subscription.

Methods

PushSubscription.getKey()
Returns an ArrayBuffer which contains the client's public key, which can then be sent to a server and used in encrypting push message data.
PushSubscription.toJSON()
Standard serializer — returns a JSON representation of the subscription properties.
PushSubscription.unsubscribe()
Starts the asynchronous process of unsubscribing from the push service, returning a Promise that resolves to a Boolean when the current subscription is successfully unregistered.

Example

navigator.serviceWorker.ready.then(function(reg) {
  reg.pushManager.getSubscription().then(function(subscription) {
    subscription.unsubscribe().then(function(successful) {
      // You've successfully unsubscribed
    }).catch(function(e) {
      // Unsubscription failed
    })
  })
});

Specifications

Specification Status Comment
Push API
The definition of 'PushSubscription' in that specification.
Working Draft Initial definition

Browser compatibility

DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
PushSubscriptionChrome Full support 42Edge Full support ≤18Firefox Full support 44
Notes
Full support 44
Notes
Notes Extended Support Releases (ESR) before Firefox 78 ESR do not support service workers and the Push API.
IE No support NoOpera Full support 29Safari No support NoWebView Android No support NoChrome Android Full support 42Firefox Android Full support 48Opera Android Full support 29Safari iOS No support NoSamsung Internet Android Full support 4.0
endpointChrome Full support 42Edge Full support 16Firefox Full support 44
Notes
Full support 44
Notes
Notes Extended Support Releases (ESR) before Firefox 78 ESR do not support service workers and the Push API.
IE No support NoOpera Full support 29Safari No support NoWebView Android No support NoChrome Android Full support 42Firefox Android Full support 48Opera Android Full support 29Safari iOS No support NoSamsung Internet Android Full support 4.0
expirationTimeChrome Full support 60Edge Full support 16Firefox No support NoIE No support NoOpera Full support 47Safari No support NoWebView Android No support NoChrome Android Full support 60Firefox Android No support NoOpera Android Full support 44Safari iOS No support NoSamsung Internet Android Full support 8.0
getKey()Chrome Full support 42Edge Full support 16Firefox Full support 44
Notes
Full support 44
Notes
Notes Extended Support Releases (ESR) before Firefox 78 ESR do not support service workers and the Push API.
IE No support NoOpera Full support 29Safari No support NoWebView Android No support NoChrome Android Full support 42Firefox Android Full support 48Opera Android Full support 29Safari iOS No support NoSamsung Internet Android Full support 4.0
optionsChrome Full support 42Edge Full support 16Firefox Full support 44
Notes
Full support 44
Notes
Notes Extended Support Releases (ESR) before Firefox 78 ESR do not support service workers and the Push API.
IE No support NoOpera Full support 29Safari No support NoWebView Android No support NoChrome Android Full support 42Firefox Android Full support 48Opera Android Full support 29Safari iOS No support NoSamsung Internet Android Full support 4.0
subscriptionIdChrome Full support 42Edge Full support ≤18Firefox No support NoIE No support NoOpera Full support 29Safari No support NoWebView Android No support NoChrome Android Full support 42Firefox Android No support NoOpera Android Full support 29Safari iOS No support NoSamsung Internet Android Full support 4.0
toJSON()Chrome Full support 42Edge Full support 17Firefox Full support 46IE No support NoOpera Full support YesSafari No support NoWebView Android No support NoChrome Android Full support 50Firefox Android Full support 48Opera Android Full support YesSafari iOS No support NoSamsung Internet Android Full support 5.0
unsubscribe()Chrome Full support 42Edge Full support 16Firefox Full support 44
Notes
Full support 44
Notes
Notes Extended Support Releases (ESR) before Firefox 78 ESR do not support service workers and the Push API.
IE No support NoOpera Full support YesSafari No support NoWebView Android No support NoChrome Android Full support 50Firefox Android Full support 48Opera Android Full support YesSafari iOS No support NoSamsung Internet Android Full support 5.0

Legend

Full support
Full support
No support
No support
See implementation notes.
See implementation notes.

See also