PushSubscription

Experimental: 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 value 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

Browser compatibility

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari WebView Android Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet
PushSubscription
42
≤18
44
Extended Support Releases (ESR) before Firefox 78 ESR do not support service workers and the Push API.
No
29
No
No
42
48
29
No
4.0
endpoint
42
16
44
Extended Support Releases (ESR) before Firefox 78 ESR do not support service workers and the Push API.
No
29
No
No
42
48
29
No
4.0
expirationTime
60
16
No
No
47
No
No
60
No
44
No
8.0
getKey
42
16
44
Extended Support Releases (ESR) before Firefox 78 ESR do not support service workers and the Push API.
No
29
No
No
42
48
29
No
4.0
options
54
17
44
Extended Support Releases (ESR) before Firefox 78 ESR do not support service workers and the Push API.
No
41
No
No
54
48
41
No
6.0
subscriptionId
42
≤18
No
No
29
No
No
42
No
29
No
4.0
toJSON
42
17
46
No
Yes
No
No
50
48
Yes
No
5.0
unsubscribe
42
16
44
Extended Support Releases (ESR) before Firefox 78 ESR do not support service workers and the Push API.
No
Yes
No
No
50
48
Yes
No
5.0

See also

© 2005–2021 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/PushSubscription