Movatterモバイル変換


[0]ホーム

URL:


  1. Web
  2. Web APIs
  3. Cookie Store API

Cookie Store API

Secure context: This feature is available only insecure contexts (HTTPS), in some or allsupporting browsers.

Note: This feature is available inService Workers.

TheCookie Store API is an asynchronous API for managing cookies, available in windows and alsoservice workers.

Concepts and Usage

The original method of getting and setting cookies involves working withdocument.cookie to get and set cookie information as a string of key/value pairs.In addition to this being cumbersome and error prone, it also has a host of issues in the context of modern web development.

Thedocument.cookie interface issynchronous, single-threaded, and blocking. When writing a cookie you must wait for the browser to update the string of all cookies. In addition, the reliance ondocument means that cookies cannot be accessed by service workers, as they cannot access thedocument object.

TheCookie Store API provides an updated method of managing cookies. It isasynchronous and promise-based, therefore does not block the event loop. It does not rely onDocument and so is available to service workers. The methods for getting and setting cookies also provide more feedback by way of error messages. This means that web developers do not have to set then immediately read back a cookie to check that setting was successful.

Interfaces

CookieStoreExperimental

TheCookieStore interface enables getting and setting cookies.

CookieStoreManagerExperimental

TheCookieStoreManager interface provides a service worker registration to enable service workers to subscribe to cookie change events.

CookieChangeEventExperimental

ACookieChangeEvent namedchange is dispatched againstCookieStore objects inWindow contexts when any script-visible cookies changes occur.

ExtendableCookieChangeEvent

AnExtendableCookieChangeEvent namedcookiechange is dispatched inServiceWorkerGlobalScope contexts when any script-visible cookie changes occur that match the service worker's cookie change subscription list.

Extensions to other interfaces

ServiceWorkerGlobalScope.cookieStoreRead onlyExperimental

Returns a reference to theCookieStore object associated with the service worker.

ServiceWorkerRegistration.cookiesRead onlyExperimental

Returns a reference to theCookieStoreManager interface, which enables a web app to subscribe to and unsubscribe from cookie change events.

Window.cookieStoreRead onlyExperimental

Returns a reference to theCookieStore object for the current document context.

cookiechange eventExperimental

Fired when any cookie changes have occurred which match the service worker's cookie change subscription list.

Specifications

Specification
Cookie Store API

Browser compatibility

api.CookieStore

api.CookieStoreManager

See also

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp