W3cubDocs

/Web APIs

PushSubscription

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

An instance of this interface can be serialized.

Instance properties

PushSubscription.endpoint Read only

A string 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 Deprecated Read only

A string containing the subscription ID associated with the push subscription.

Instance 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

js

navigator.serviceWorker.ready.then((reg) => {
  reg.pushManager.getSubscription().then((subscription) => {
    subscription
      .unsubscribe()
      .then((successful) => {
        // You've successfully unsubscribed
      })
      .catch((e) => {
        // Unsubscribing 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 17 44 No 29
16Supported on macOS 13 and later
No 42 48 29 16.4 4.0
endpoint 42 17 44 No 29
16Supported on macOS 13 and later
No 42 48 29 16.4 4.0
expirationTime 60 17 96 No 47
16Supported on macOS 13 and later
No 60 96 44 16.4 8.0
getKey 42 17 44 No 29
16Supported on macOS 13 and later
No 42 48 29 16.4 4.0
options 54 17 44 No 41
16Supported on macOS 13 and later
No 54 48 41 16.4 6.0
subscriptionId 42 17 No No 29 No No 42 No 29 No 4.0
toJSON 42 17 44 No 29
16Supported on macOS 13 and later
No 50 48 37 16.4 5.0
unsubscribe 42 17 44 No 29
16Supported on macOS 13 and later
No 50 48 37 16.4 5.0

See also

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