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.endpointRead only- A
USVStringcontaining the endpoint associated with the push subscription. PushSubscription.expirationTimeRead only- A
DOMHighResTimeStampof the subscription expiration time associated with the push subscription, if there is one, or null otherwise. PushSubscription.optionsRead only- An object containing the options used to create the subscription.
PushSubscription.subscriptionIdRead only- A
DOMStringcontaining the subscription ID associated with the push subscription.
Methods
PushSubscription.getKey()- Returns an
ArrayBufferwhich 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
Promisethat resolves to aBooleanwhen 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
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
PushSubscription | Chrome Full support 42 | Edge Full support ≤18 | Firefox
Full support
44
| IE No support No | Opera Full support 29 | Safari No support No | WebView Android No support No | Chrome Android Full support 42 | Firefox Android Full support 48 | Opera Android Full support 29 | Safari iOS No support No | Samsung Internet Android Full support 4.0 |
endpoint | Chrome Full support 42 | Edge Full support 16 | Firefox
Full support
44
| IE No support No | Opera Full support 29 | Safari No support No | WebView Android No support No | Chrome Android Full support 42 | Firefox Android Full support 48 | Opera Android Full support 29 | Safari iOS No support No | Samsung Internet Android Full support 4.0 |
expirationTime | Chrome Full support 60 | Edge Full support 16 | Firefox No support No | IE No support No | Opera Full support 47 | Safari No support No | WebView Android No support No | Chrome Android Full support 60 | Firefox Android No support No | Opera Android Full support 44 | Safari iOS No support No | Samsung Internet Android Full support 8.0 |
getKey() | Chrome Full support 42 | Edge Full support 16 | Firefox
Full support
44
| IE No support No | Opera Full support 29 | Safari No support No | WebView Android No support No | Chrome Android Full support 42 | Firefox Android Full support 48 | Opera Android Full support 29 | Safari iOS No support No | Samsung Internet Android Full support 4.0 |
options | Chrome Full support 42 | Edge Full support 16 | Firefox
Full support
44
| IE No support No | Opera Full support 29 | Safari No support No | WebView Android No support No | Chrome Android Full support 42 | Firefox Android Full support 48 | Opera Android Full support 29 | Safari iOS No support No | Samsung Internet Android Full support 4.0 |
subscriptionId | Chrome Full support 42 | Edge Full support ≤18 | Firefox No support No | IE No support No | Opera Full support 29 | Safari No support No | WebView Android No support No | Chrome Android Full support 42 | Firefox Android No support No | Opera Android Full support 29 | Safari iOS No support No | Samsung Internet Android Full support 4.0 |
toJSON() | Chrome Full support 42 | Edge Full support 17 | Firefox Full support 46 | IE No support No | Opera Full support Yes | Safari No support No | WebView Android No support No | Chrome Android Full support 50 | Firefox Android Full support 48 | Opera Android Full support Yes | Safari iOS No support No | Samsung Internet Android Full support 5.0 |
unsubscribe() | Chrome Full support 42 | Edge Full support 16 | Firefox
Full support
44
| IE No support No | Opera Full support Yes | Safari No support No | WebView Android No support No | Chrome Android Full support 50 | Firefox Android Full support 48 | Opera Android Full support Yes | Safari iOS No support No | Samsung Internet Android Full support 5.0 |
Legend
- Full support
- Full support
- No support
- No support
- See implementation notes.
- See implementation notes.
