PushSubscription.unsubscribe()

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

The unsubscribe() method of the PushSubscription interface returns a Promise that resolves to a boolean value when the current subscription is successfully unsubscribed.

Syntax

PushSubscription.unsubscribe().then(function(Boolean) { ... });

Parameters

None.

Returns

A Promise that resolves to a boolean value when the current subscription is successfully unsubscribed.

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
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/unsubscribe