Back to Content

PushSubscription: unsubscribe() method

files/en-us/web/api/pushsubscription/unsubscribe/index.md

latest934 B
Original Source

{{APIRef("Push API")}}{{SecureContext_Header}}{{AvailableInWorkers}}

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

Syntax

js-nolint
unsubscribe()

Parameters

None.

Return value

A {{jsxref("Promise")}} that resolves to a boolean value when the current subscription is successfully unsubscribed.

Examples

js
navigator.serviceWorker.ready.then((reg) => {
  reg.pushManager.getSubscription().then((subscription) => {
    subscription
      .unsubscribe()
      .then((successful) => {
        // You've successfully unsubscribed
      })
      .catch((e) => {
        // Unsubscribing failed
      });
  });
});

Specifications

{{Specifications}}

Browser compatibility

{{Compat}}

See also

  • {{domxref("PushManager.getSubscription")}}