Skip to content

Latest commit

 

History

History
54 lines (35 loc) · 1.47 KB

File metadata and controls

54 lines (35 loc) · 1.47 KB
title short-title slug page-type browser-compat
CookieStoreManager: unsubscribe() method
unsubscribe()
Web/API/CookieStoreManager/unsubscribe
web-api-instance-method
api.CookieStoreManager.unsubscribe

{{securecontext_header}}{{APIRef("Cookie Store API")}}{{AvailableInWorkers("window_and_service")}}

The unsubscribe() method of the {{domxref("CookieStoreManager")}} interface stops the {{domxref("ServiceWorkerRegistration")}} from receiving previously subscribed events.

Syntax

unsubscribe(subscriptions)

Parameters

  • subscriptions

    • : An object containing:

      • name
        • : A string with the name of a cookie.
      • url
        • : A string with the url of the scope used to subscribe to this cookie.

Return value

A {{jsxref("Promise")}} that resolves with {{jsxref("undefined")}} when the service worker has been unsubscribed.

Exceptions

  • {{jsxref("TypeError")}}
    • : Thrown if the URL passed in subscriptions does not match the service worker registration's {{domxref("ServiceWorkerRegistration.scope","scope")}}.

Examples

In this example, the {{domxref("ServiceWorkerRegistration")}} represented by registration is unsubscribing from change events on the cookie named "cookie1" with a scope of "/path1".

const subscriptions = [{ name: "cookie1", url: `/path1` }];
await registration.cookies.unsubscribe(subscriptions);

Specifications

{{Specifications}}

Browser compatibility

{{Compat}}