W3cubDocs

/DOM

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 compatibilityUpdate compatibility data on GitHub

Desktop
Chrome Edge Firefox Internet Explorer Opera Safari
Basic support 42 Yes 44
44
Service workers (and Push) have been disabled in the Firefox 45 & 52 Extended Support Releases (ESR).
No 29 No
endpoint 42 16 44
44
Service workers (and Push) have been disabled in the Firefox 45 & 52 Extended Support Releases (ESR).
No 29 No
expirationTime 60 16 ? No 47 No
options 42 16 44
44
Service workers (and Push) have been disabled in the Firefox 45 & 52 Extended Support Releases (ESR).
No 29 No
subscriptionId 42 Yes 44
44
Service workers (and Push) have been disabled in the Firefox 45 & 52 Extended Support Releases (ESR).
No 29 No
getKey 42 16 44
44
Service workers (and Push) have been disabled in the Firefox 45 & 52 Extended Support Releases (ESR).
No 29 No
toJSON 42 ? ? No ? ?
unsubscribe 42 16 ? No ? ?
Mobile
Android webview Chrome for Android Edge Mobile Firefox for Android Opera for Android iOS Safari Samsung Internet
Basic support No 42 ? 48 29 No 4.0
endpoint No 42 ? 48 29 No 4.0
expirationTime No 60 ? ? 47 No No
options No 42 ? 48 29 No 4.0
subscriptionId No 42 ? 48 29 No 4.0
getKey No 42 ? 48 29 No 4.0
toJSON No 50 ? ? ? ? 5.0
unsubscribe No 50 ? ? ? ? 5.0

See also

© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/PushSubscription