Cookie Store API
The Cookie Store API provides an asychronous API for managing cookies, while also exposing cookies to
The existing method of getting and setting cookies involves working with
document.cookie 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.
document.cookie interface is synchronous, 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 on
document means that cookies cannot be accessed by service workers which cannot access the
The Cookie Store API provides an updated method of managing cookies. It is asynchronous and promise-based, therefore does not block the event loop. It does not rely on
document 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.
CookieChangeEventis dispatched against
Windowcontexts when any script-visible cookies changes occur.
ExtendableCookieChangeEventis dispatched against
ServiceWorkerGlobalScopeevents when any script-visible cookie changes have occured which match the service worker's cookie change subscription list.
|Cookie Store API||Draft||Initial definition.|
BCD tables only load in the browser