diff --git a/files/en-us/web/api/cookie_store_api/index.md b/files/en-us/web/api/cookie_store_api/index.md index 0c1a9eb897f85ac..2d4e479da4496e0 100644 --- a/files/en-us/web/api/cookie_store_api/index.md +++ b/files/en-us/web/api/cookie_store_api/index.md @@ -4,31 +4,47 @@ slug: Web/API/Cookie_Store_API page-type: web-api-overview status: - experimental -browser-compat: api.CookieStore +browser-compat: + - api.CookieChangeEvent + - api.CookieStore + - api.CookieStoreManager + - api.ExtendableCookieChangeEvent +spec-urls: https://wicg.github.io/cookie-store/ --- {{securecontext_header}}{{DefaultAPISidebar("Cookie Store API")}}{{SeeCompatTable}} -The _**Cookie Store API**_ provides an asynchronous API for managing cookies, while also exposing cookies to [Service Worker API](/en-US/docs/Web/API/Service_Worker_API), +The _**Cookie Store API**_ provides an asynchronous API for managing cookies, while also exposing cookies to {{domxref("Service Worker API", "", "", "nocode")}}. ## Concepts and Usage The existing method of getting and setting cookies involves working with {{domxref("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. -The `document.cookie` interface is {{Glossary("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 {{domxref("document")}} means that cookies cannot be accessed by service workers which cannot access the `document` object. +The `document.cookie` interface is {{Glossary("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 {{domxref("document")}} means that cookies cannot be accessed by service workers which cannot access the {{domxref("document")}} object. The _Cookie Store API_ provides an updated method of managing cookies. It is {{Glossary("asynchronous")}} and promise-based, therefore does not block the event loop. It does not rely on {{domxref("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. ## Interfaces -- {{domxref("CookieStore")}} +- {{domxref("CookieChangeEvent")}} {{Experimental_Inline}} + - : A `CookieChangeEvent` named `change` is dispatched against `CookieStore` object in {{domxref("Window")}} context when any script-visible cookies changes occur. +- {{domxref("CookieStore")}} {{Experimental_Inline}} - : The `CookieStore` interface enables getting and setting cookies. -- {{domxref("CookieStoreManager")}} +- {{domxref("CookieStoreManager")}} {{Experimental_Inline}} - : The `CookieStoreManager` interface provides a service worker registration to enable service workers to subscribe to cookie change events. -- {{domxref("CookieChangeEvent")}} - - : A `CookieChangeEvent` named `change` is dispatched against `CookieStore` objects in {{domxref("Window")}} contexts when any script-visible cookies changes occur. - {{domxref("ExtendableCookieChangeEvent")}} - - : An `ExtendableCookieChangeEvent` named `change` is dispatched against {{domxref("ServiceWorkerGlobalScope")}} events when any script-visible cookie changes occur that match the service worker's cookie change subscription list. + - : An `ExtendableCookieChangeEvent` named `cookiechange` is dispatched against {{domxref("ServiceWorkerGlobalScope")}} context when any script-visible cookie changes occur that match the service worker's cookie change subscription list. + +### Extensions to other interfaces + +- {{domxref("ServiceWorkerGlobalScope/cookiechange_event", "cookiechange")}} {{Experimental_Inline}} + - : Fired when any cookie changes have occurred which match the Service Worker's cookie change subscription list added via {{domxref("CookieStoreManager.subscribe()")}}. +- {{domxref("ServiceWorkerGlobalScope.cookieStore")}} {{ReadOnlyInline}} {{Experimental_Inline}} + - : Returns a reference to the {{domxref("CookieStore")}} object associated with the service worker. +- {{domxref("ServiceWorkerRegistration.cookies")}} {{ReadOnlyInline}} {{Experimental_Inline}} + - : Returns a reference to the {{domxref("CookieStoreManager")}} interface, which allows subscribe and unsubscribe to cookie change events. +- {{domxref("Window.cookieStore")}} {{ReadOnlyInline}} {{Experimental_Inline}} + - : Returns a reference to the {{domxref("CookieStore")}} object for the current document context. ## Specifications diff --git a/files/en-us/web/api/cookiechangeevent/changed/index.md b/files/en-us/web/api/cookiechangeevent/changed/index.md index 202125d5725cf3d..1d2cc020b47cccd 100644 --- a/files/en-us/web/api/cookiechangeevent/changed/index.md +++ b/files/en-us/web/api/cookiechangeevent/changed/index.md @@ -25,7 +25,7 @@ An array of objects containing the changed cookie(s). Each object contains the f - `path` - : A string containing the path of the cookie. - `expires` - - : A timestamp, given as [Unix time](/en-US/docs/Glossary/Unix_time) in milliseconds, containing the expiration date of the cookie. + - : A timestamp, given as {{glossary("Unix time")}} in milliseconds, containing the expiration date of the cookie. - `secure` - : A {{jsxref("boolean")}} indicating whether the cookie is from a site with a secure context (HTTPS rather than HTTP). - `sameSite` @@ -39,17 +39,21 @@ An array of objects containing the changed cookie(s). Each object contains the f - `"none"` - : Cookies will be sent in all contexts. +- `partitioned` + - : A boolean indicating whether the cookie is a partitioned cookie (`true`) or not (`false`). See [Cookies Having Independent Partitioned State (CHIPS)](/en-US/docs/Web/Privacy/Partitioned_cookies) for more information. + ## Examples -In this example when the cookie is set, the event listener logs the `changed` property to the console. The first item in that array contains an object representing the cookie that has just been set. +In this example, when the cookie is set, the event listener logs the `changed` property to the console. The first item in that array contains an object representing the cookie that has just been set. ```js -cookieStore.addEventListener("change", (event) => { +window.cookieStore.addEventListener("change", (event) => { console.log(event.changed[0]); }); const one_day = 24 * 60 * 60 * 1000; -cookieStore.set({ + +window.cookieStore.set({ name: "cookie1", value: "cookie1-value", expires: Date.now() + one_day, diff --git a/files/en-us/web/api/cookiechangeevent/cookiechangeevent/index.md b/files/en-us/web/api/cookiechangeevent/cookiechangeevent/index.md index eeb08e89884436b..d6df912446c039c 100644 --- a/files/en-us/web/api/cookiechangeevent/cookiechangeevent/index.md +++ b/files/en-us/web/api/cookiechangeevent/cookiechangeevent/index.md @@ -11,7 +11,7 @@ browser-compat: api.CookieChangeEvent.CookieChangeEvent {{securecontext_header}}{{APIRef("Cookie Store API")}}{{SeeCompatTable}} The **`CookieChangeEvent()`** constructor creates a new {{domxref("CookieChangeEvent")}} object -which is the event type passed to {{domxref("CookieStore/change_event", "CookieStore.onchange()")}}. +which is the event type passed to {{domxref("CookieStore/change_event", "change")}} event. This constructor is called by the browser when a change event occurs. > **Note:** This event constructor is generally not needed for production websites. It's primary use is for tests that require an instance of this event. @@ -26,13 +26,12 @@ new CookieChangeEvent(type, options) ### Parameters - `type` - - : A string with the name of the event. - It is case-sensitive and browsers always set it to `cookiechange`. + - : A string with the name of the event. It is case-sensitive and browsers always set it to `change`. - `options` {{Optional_Inline}} - : An object that, _in addition of the properties defined in {{domxref("Event/Event", "Event()")}}_, can have the following properties: - - `changed` + - `changed` {{Optional_Inline}} - : An array containing the changed cookies. - - `deleted` + - `deleted` {{Optional_Inline}} - : An array containing the deleted cookies. ### Return value diff --git a/files/en-us/web/api/cookiechangeevent/deleted/index.md b/files/en-us/web/api/cookiechangeevent/deleted/index.md index b129e5d2a90cd5b..95158160dde3607 100644 --- a/files/en-us/web/api/cookiechangeevent/deleted/index.md +++ b/files/en-us/web/api/cookiechangeevent/deleted/index.md @@ -25,7 +25,7 @@ An array of objects containing the deleted cookie(s). Each object contains the f - `path` - : A string containing the path of the cookie. - `expires` - - : A timestamp, given as [Unix time](/en-US/docs/Glossary/Unix_time) in milliseconds, containing the expiration date of the cookie. + - : A timestamp, given as {{glossary("Unix time")}} in milliseconds, containing the expiration date of the cookie. - `secure` - : A {{jsxref("boolean")}} indicating whether the cookie is from a site with a secure context (HTTPS rather than HTTP). - `sameSite` @@ -39,12 +39,15 @@ An array of objects containing the deleted cookie(s). Each object contains the f - `"none"` - : Cookies will be sent in all contexts. +- `partitioned` + - : A boolean indicating whether the cookie is a partitioned cookie (`true`) or not (`false`). See [Cookies Having Independent Partitioned State (CHIPS)](/en-US/docs/Web/Privacy/Partitioned_cookies) for more information. + ## Examples -In this example when the cookie is deleted the event listener logs the first item in the `CookieChangeEvent.deleted` property to the console. It contains an object representing the cookie that has just been deleted. +In this example, when the cookie is deleted, the event listener logs the first item in the `CookieChangeEvent.deleted` property to the console. It contains an object representing the cookie that has just been deleted. ```js -cookieStore.addEventListener("change", (event) => { +window.cookieStore.addEventListener("change", (event) => { console.log(event.deleted[0]); }); ``` diff --git a/files/en-us/web/api/cookiechangeevent/index.md b/files/en-us/web/api/cookiechangeevent/index.md index 6f0130249ef9b99..86007c9f388f414 100644 --- a/files/en-us/web/api/cookiechangeevent/index.md +++ b/files/en-us/web/api/cookiechangeevent/index.md @@ -9,12 +9,12 @@ browser-compat: api.CookieChangeEvent {{securecontext_header}}{{APIRef("Cookie Store API")}}{{SeeCompatTable}} -The **`CookieChangeEvent`** interface of the ['Cookie Store API'](/en-US/docs/Web/API/Cookie_Store_API) is the event type of the {{domxref("CookieStore.change_event", "change")}} event fired at a {{domxref("CookieStore")}} when any cookie changes occur. A cookie change consists of a cookie and a type (either "changed" or "deleted"). +The **`CookieChangeEvent`** interface of the {{domxref("Cookie Store API", "", "", "nocode")}} is the event type passed to {{domxref("CookieStore.change_event", "change")}} event fired at the {{domxref("CookieStore")}} when any cookie changes occur. A cookie change consists of a cookie and a type (either "changed" or "deleted"). Cookie changes that will cause the `CookieChangeEvent` to be dispatched are: - A cookie is newly created and not immediately removed. In this case `type` is "changed". -- A cookie is newly created and immediately removed. In this case `type` is "deleted" +- A cookie is newly created and immediately removed. In this case `type` is "deleted". - A cookie is removed. In this case `type` is "deleted". > **Note:** A cookie that is replaced due to the insertion of another cookie with the same name, domain, and path, is ignored and does not trigger a change event. @@ -35,17 +35,22 @@ _This interface also inherits properties from {{domxref("Event")}}._ - {{domxref("CookieChangeEvent.deleted")}} {{ReadOnlyInline}} {{Experimental_Inline}} - : Returns an array containing one or more deleted cookies. +## Instance methods + +_This interface also inherits methods from {{domxref("Event")}}._ + ## Examples In this example when the cookie is set, the event listener logs the event to the console. This is a `CookieChangeEvent` object with the {{domxref("CookieChangeEvent.changed","changed")}} property containing an object representing the cookie that has just been set. ```js -cookieStore.addEventListener("change", (event) => { +window.cookieStore.addEventListener("change", (event) => { console.log(event); }); const one_day = 24 * 60 * 60 * 1000; -cookieStore.set({ + +window.cookieStore.set({ name: "cookie1", value: "cookie1-value", expires: Date.now() + one_day, diff --git a/files/en-us/web/api/cookiestore/change_event/index.md b/files/en-us/web/api/cookiestore/change_event/index.md index 9ffb29511d1b491..ee55b8b430767f1 100644 --- a/files/en-us/web/api/cookiestore/change_event/index.md +++ b/files/en-us/web/api/cookiestore/change_event/index.md @@ -22,12 +22,18 @@ cookieStore.addEventListener("change", (event) => { }) cookieStore.onchange = (event) => { } ``` +## Event type + +A {{domxref("CookieChangeEvent")}}. Inherits from {{domxref("Event")}}. + +{{InheritanceDiagram("CookieChangeEvent")}} + ## Examples -To be informed when a cookie has changed, you can add a handler to the `cookieStore` instance using {{domxref("EventTarget.addEventListener", "addEventListener()")}}, like this: +To be informed when a cookie has changed, you can add a handler to the `CookieStore` instance using {{domxref("EventTarget.addEventListener", "addEventListener()")}}, like this: ```js -cookieStore.addEventListener("change", (event) => { +window.cookieStore.addEventListener("change", (event) => { console.log("1 change event"); }); ``` @@ -35,7 +41,7 @@ cookieStore.addEventListener("change", (event) => { Alternatively, you can use the `CookieStore.onchange` event handler property to establish a handler for the `change` event: ```js -cookieStore.onchange = (event) => { +window.cookieStore.onchange = (event) => { console.log("1 change event"); }; ``` diff --git a/files/en-us/web/api/cookiestore/delete/index.md b/files/en-us/web/api/cookiestore/delete/index.md index 5655ac11c98dfab..4bdc985880c72ec 100644 --- a/files/en-us/web/api/cookiestore/delete/index.md +++ b/files/en-us/web/api/cookiestore/delete/index.md @@ -8,7 +8,7 @@ status: browser-compat: api.CookieStore.delete --- -{{securecontext_header}}{{APIRef("Cookie Store API")}}{{SeeCompatTable}} +{{securecontext_header}}{{APIRef("Cookie Store API")}}{{SeeCompatTable}}{{AvailableInWorkers}} The **`delete()`** method of the {{domxref("CookieStore")}} interface deletes a cookie with the given name or options object. The `delete()` method expires the cookie by changing the date to one in the past. @@ -23,23 +23,23 @@ delete(options) This method requires one of the following: -- `name` +- `name` {{optional_inline}} - : A string with the name of a cookie. Or -- `options` +- `options` {{optional_inline}} - : An object containing: - `name` - : A string with the name of a cookie. + - `domain` {{Optional_Inline}} + - : A string with the URL of a cookie. Defaults to `null`. + - `path` {{Optional_Inline}} + - : A string containing a path. Defaults to `/`. - `partitioned` {{Optional_Inline}} - : A boolean value that defaults to `false`. Setting it to `true` specifies that the cookie to delete will be a partitioned cookie. See [Cookies Having Independent Partitioned State (CHIPS)](/en-US/docs/Web/Privacy/Partitioned_cookies) for more information. - - `path` {{Optional_Inline}} - - : A string containing a path. - - `url` {{Optional_Inline}} - - : A string with the URL of a cookie. > **Note:** The `url` option enables the modification of a cookie scoped under a particular URL. Service workers can obtain cookies that would be sent to any URL under their scope. From a document you may only obtain the cookies at the current URL, so the only valid URL in a document context is the document's URL. @@ -49,15 +49,18 @@ A {{jsxref("Promise")}} that resolves with {{jsxref("undefined")}} when deletion ### Exceptions +- `SecurityError` {{domxref("DOMException")}} + - : Thrown if the origin can not {{glossary("Serialization", "serialize")}} to a URL. - {{jsxref("TypeError")}} - : Thrown if deleting the cookie represented by the given `name` or `options` fails. ## Examples -In this example a cookie is deleted by passing the name to the `delete()` method. +In this example, a cookie is deleted by passing the name to the `delete()` method. ```js -let result = cookieStore.delete("cookie1"); +let result = window.cookieStore.delete("cookie1"); + console.log(result); ``` diff --git a/files/en-us/web/api/cookiestore/get/index.md b/files/en-us/web/api/cookiestore/get/index.md index ddc1111c1810fc3..e2e4997f727f27a 100644 --- a/files/en-us/web/api/cookiestore/get/index.md +++ b/files/en-us/web/api/cookiestore/get/index.md @@ -8,7 +8,7 @@ status: browser-compat: api.CookieStore.get --- -{{securecontext_header}}{{APIRef("Cookie Store API")}}{{SeeCompatTable}} +{{securecontext_header}}{{APIRef("Cookie Store API")}}{{SeeCompatTable}}{{AvailableInWorkers}} The **`get()`** method of the {{domxref("CookieStore")}} interface returns a single cookie with the given name or options object. The method will return the first matching cookie for the passed parameters. @@ -23,12 +23,12 @@ get(options) This method requires one of the following: -- `name` +- `name` {{optional_inline}} - : A string with the name of a cookie. Or -- `options` +- `options` {{optional_inline}} - : An object containing: @@ -49,7 +49,7 @@ A {{jsxref("Promise")}} that resolves with an object representing the first cook - `expires` - - : A timestamp, given as [Unix time](/en-US/docs/Glossary/Unix_time) in milliseconds, containing the expiration date of the cookie. + - : A timestamp, given as {{glossary("Unix time")}} in milliseconds, containing the expiration date of the cookie. - `name` @@ -83,15 +83,22 @@ A {{jsxref("Promise")}} that resolves with an object representing the first cook ### Exceptions +- `SecurityError` {{domxref("DOMException")}} + - : Thrown if the origin does not {{glossary("Serialization", "serialize")}} to a URL. - {{jsxref("TypeError")}} - - : Thrown if getting the cookie represented by the given `name` or `options` fails. + - : Thrown if: + - The passing `options` is an empty object. + - The `url` in `options` is present and is not equal with the creation URL if in Window context. + - The `url` in `options` is present and its origin is same as the origin of the creation URL. + - Getting the cookie or cookies represented by the given `name` or `options` fails. ## Examples -In this example we return a cookie named "cookie1". If the cookie is found the result of the Promise is an object containing the details of a single cookie. +In this example, we return a cookie named "cookie1". If the cookie is found the result of the Promise is an object containing the details of a single cookie. ```js -let cookie = cookieStore.get("cookie1"); +let cookie = await window.cookieStore.get("cookie1"); + if (cookie) { console.log(cookie); } else { diff --git a/files/en-us/web/api/cookiestore/getall/index.md b/files/en-us/web/api/cookiestore/getall/index.md index 07d593c8a9567bb..665412456174816 100644 --- a/files/en-us/web/api/cookiestore/getall/index.md +++ b/files/en-us/web/api/cookiestore/getall/index.md @@ -8,7 +8,7 @@ status: browser-compat: api.CookieStore.getAll --- -{{securecontext_header}}{{APIRef("Cookie Store API")}}{{SeeCompatTable}} +{{securecontext_header}}{{APIRef("Cookie Store API")}}{{SeeCompatTable}}{{AvailableInWorkers}} The **`getAll()`** method of the {{domxref("CookieStore")}} interface returns a list of cookies that match the name or options passed to it. Passing no parameters will return all cookies for the current context. @@ -49,7 +49,7 @@ Each object contains the following properties: - `expires` - - : A timestamp, given as [Unix time](/en-US/docs/Glossary/Unix_time) in milliseconds, containing the expiration date of the cookie. + - : A timestamp, given as {{glossary("Unix time")}} in milliseconds, containing the expiration date of the cookie. - `name` @@ -83,16 +83,22 @@ Each object contains the following properties: ### Exceptions +- `SecurityError` {{domxref("DOMException")}} + - : Thrown if the origin does not {{glossary("Serialization", "serialize")}} to a URL. - {{jsxref("TypeError")}} - - : Thrown if getting the cookie or cookies represented by the given `name` or `options` fails. + - : Thrown if: + - The `url` member of `options` parameter is present and is not equal with the creation URL if in Window context. + - The `url` member of `options` parameter is present and its origin is same as the origin of the creation URL. + - Getting the cookie or cookies represented by the given `name` or `options` fails. ## Examples -In this example we use `getAll()` with no parameters. This returns all of the cookies for this context as an array of objects. +In this example, we use `getAll()` with no parameters. This returns all of the cookies for this context as an array of objects. ```js -let cookies = await cookieStore.getAll(); -if (cookies) { +let cookies = await window.cookieStore.getAll(); + +if (cookies.length > 0) { console.log(cookies); } else { console.log("Cookie not found"); diff --git a/files/en-us/web/api/cookiestore/index.md b/files/en-us/web/api/cookiestore/index.md index b6b403d00750398..51108e4c78a7d2c 100644 --- a/files/en-us/web/api/cookiestore/index.md +++ b/files/en-us/web/api/cookiestore/index.md @@ -7,9 +7,9 @@ status: browser-compat: api.CookieStore --- -{{securecontext_header}}{{APIRef("Cookie Store API")}}{{SeeCompatTable}} +{{securecontext_header}}{{APIRef("Cookie Store API")}}{{SeeCompatTable}}{{AvailableInWorkers}} -The **`CookieStore`** interface of the ['Cookie Store API'](/en-US/docs/Web/API/Cookie_Store_API) provides methods for getting and setting cookies asynchronously from either a page or a service worker. +The **`CookieStore`** interface of the {{domxref("Cookie Store API", "", "", "nocode")}} provides methods for getting and setting cookies asynchronously from either a page or a service worker. The `CookieStore` is accessed via attributes in the global scope in a {{domxref("Window")}} or {{domxref("ServiceWorkerGlobalScope")}} context. Therefore there is no constructor. @@ -37,7 +37,8 @@ In this example we set a cookie and write to the console feedback as to whether ```js const day = 24 * 60 * 60 * 1000; -cookieStore + +window.cookieStore .set({ name: "cookie1", value: "cookie1-value", diff --git a/files/en-us/web/api/cookiestore/set/index.md b/files/en-us/web/api/cookiestore/set/index.md index c2a2f7fe5706285..aec99b38d95580e 100644 --- a/files/en-us/web/api/cookiestore/set/index.md +++ b/files/en-us/web/api/cookiestore/set/index.md @@ -8,7 +8,7 @@ status: browser-compat: api.CookieStore.set --- -{{securecontext_header}}{{APIRef("Cookie Store API")}}{{SeeCompatTable}} +{{securecontext_header}}{{APIRef("Cookie Store API")}}{{SeeCompatTable}}{{AvailableInWorkers}} The **`set()`** method of the {{domxref("CookieStore")}} interface sets a cookie with the given name and value or options object. @@ -23,33 +23,33 @@ set(options) This method requires one of the following: -- `name` +- `name` {{optional_inline}} - : A string with the name of the cookie. -- `value` +- `value` {{optional_inline}} - : A string with the value of the cookie. Or -- `options` +- `options` {{optional_inline}} - : An object containing: - `domain` {{Optional_Inline}} - - : A string containing the domain of the cookie. + - : A string containing the domain of the cookie. Defaults to `null`. - `expires` {{Optional_Inline}} - - : A timestamp, given as [Unix time](/en-US/docs/Glossary/Unix_time) in milliseconds, containing the expiration date of the cookie. + - : A timestamp, given as {{glossary("Unix time")}} in milliseconds, containing the expiration date of the cookie. Defaults to `null`. - `name` - : A string with the name of a cookie. - `partitioned` {{Optional_Inline}} - - : A boolean value that defaults to `false`. If set to `true`, the set cookie will be a partitioned cookie. See [Cookies Having Independent Partitioned State (CHIPS)](/en-US/docs/Web/Privacy/Partitioned_cookies) for more information. + - : A boolean value that defaults to `false`. If set to `true`, the set cookie will be a partitioned cookie. See [Cookies Having Independent Partitioned State (CHIPS)](/en-US/docs/Web/Privacy/Partitioned_cookies) for more information. Defaults to `false`. - `path` {{Optional_Inline}} - - : A string containing the path of the cookie. + - : A string containing the path of the cookie. Defaults to `/`. - `sameSite` {{Optional_Inline}} - : One of the following [`SameSite`](/en-US/docs/Web/HTTP/Headers/Set-Cookie#samesitesamesite-value) values: - `"strict"` - - : Cookies will only be sent in a first-party context and not be sent along with requests initiated by third party websites. + - : Cookies will only be sent in a first-party context and not be sent along with requests initiated by third party websites. This is the default value if not specificed. - `"lax"` - : Cookies are not sent on normal cross-site subrequests (for example to load images or frames into a third party site), but are sent when a user is navigating to the origin site (i.e. when following a link). - `"none"` @@ -64,10 +64,10 @@ A {{jsxref("Promise")}} that resolves with {{jsxref("undefined")}} when setting ### Exceptions -- {{jsxref("TypeError")}} - - : Thrown if setting the cookie with the given values fails. - `SecurityError` {{domxref("DOMException")}} - - : Thrown if the origin does not {{glossary("Serialization", "serialize")}} to a URL. + - : Thrown if the origin can not {{glossary("Serialization", "serialize")}} to a URL. +- {{jsxref("TypeError")}} + - : Thrown if setting the cookie with the given `name` and `value` or `options` fails. ## Examples @@ -75,7 +75,8 @@ The following example sets a cookie by passing an object with `name`, `value`, ` ```js const day = 24 * 60 * 60 * 1000; -cookieStore.set({ + +window.cookieStore.set({ name: "cookie1", value: "cookie1-value", expires: Date.now() + day, diff --git a/files/en-us/web/api/cookiestoremanager/getsubscriptions/index.md b/files/en-us/web/api/cookiestoremanager/getsubscriptions/index.md index 26de04fa8835332..44a053d0ade18ec 100644 --- a/files/en-us/web/api/cookiestoremanager/getsubscriptions/index.md +++ b/files/en-us/web/api/cookiestoremanager/getsubscriptions/index.md @@ -8,7 +8,7 @@ status: browser-compat: api.CookieStoreManager.getSubscriptions --- -{{securecontext_header}}{{APIRef("Cookie Store")}}{{SeeCompatTable}} +{{securecontext_header}}{{APIRef("Cookie Store API")}}{{SeeCompatTable}}{{AvailableInWorkers}} The **`getSubscriptions()`** method of the {{domxref("CookieStoreManager")}} interface returns a list of all the cookie change subscriptions for this {{domxref("ServiceWorkerRegistration")}}. @@ -24,7 +24,7 @@ None. ### Return value -A {{jsxref("promise")}} that resolves with a list of objects, each containing: +A {{jsxref("Promise")}} that resolves with a list of objects, each containing: - `name` - : A string with the name of a cookie. @@ -33,10 +33,10 @@ A {{jsxref("promise")}} that resolves with a list of objects, each containing: ## Examples -If the {{domxref("ServiceWorkerRegistration")}} represented by `registration` has subscribed to any cookie change events `subscriptions` will resolve to a list of objects containing the name and URL of those cookies. +If the {{domxref("ServiceWorkerRegistration")}} represented by `registration` has subscribed to any cookie change events, `subscriptions` will resolve to a list of objects containing the name and URL of those cookies. ```js -const subscriptions = await registration.cookies.getSubscriptions(); +const subscriptions = await self.registration.cookies.getSubscriptions(); ``` ## Specifications diff --git a/files/en-us/web/api/cookiestoremanager/index.md b/files/en-us/web/api/cookiestoremanager/index.md index 23894f7ed4e60f2..a403c8c0accd8c0 100644 --- a/files/en-us/web/api/cookiestoremanager/index.md +++ b/files/en-us/web/api/cookiestoremanager/index.md @@ -7,9 +7,9 @@ status: browser-compat: api.CookieStoreManager --- -{{securecontext_header}}{{APIRef("Cookie Store")}}{{SeeCompatTable}} +{{securecontext_header}}{{APIRef("Cookie Store API")}}{{SeeCompatTable}}{{AvailableInWorkers}} -The **`CookieStoreManager`** interface of the ['Cookie Store API'](/en-US/docs/Web/API/Cookie_Store_API) allows service workers to subscribe to cookie change events. Call {{domxref("CookieStoreManager.subscribe()","subscribe()")}} on a particular service worker registration to receive change events. +The **`CookieStoreManager`** interface of the {{domxref("Cookie Store API", "", "", "nocode")}} allows service workers to subscribe to cookie change events. Call {{domxref("CookieStoreManager.subscribe()","subscribe()")}} on a particular service worker registration to receive change events. A `CookieStoreManager` has an associated {{domxref("ServiceWorkerRegistration")}}. Each service worker registration has a cookie change subscription list, which is a list of cookie change subscriptions each containing a name and URL. The methods in this interface allow the service worker to add and remove subscriptions from this list, and to get a list of all subscriptions. @@ -18,25 +18,26 @@ To get a `CookieStoreManager`, call {{domxref("ServiceWorkerRegistration.cookies ## Instance methods - {{domxref("CookieStoreManager.getSubscriptions()")}} {{Experimental_Inline}} - - : Returns a {{jsxref("promise")}} which resolves to a list of the cookie change subscriptions for this service worker registration. + - : Returns a {{jsxref("Promise")}} which resolves to a list of the cookie change subscriptions for this service worker registration. - {{domxref("CookieStoreManager.subscribe()")}} {{Experimental_Inline}} - - : Subscribes to changes to cookies. It returns a {{jsxref("promise")}} which resolves when the subscription is successful. + - : Subscribes to changes to cookies. It returns a {{jsxref("Promise")}} which resolves when the subscription is successful. - {{domxref("CookieStoreManager.unsubscribe()")}} {{Experimental_Inline}} - - : Unsubscribes the registered service worker from changes to cookies. It returns a {{jsxref("promise")}} which resolves when the operation is successful. + - : Unsubscribes the registered service worker from changes to cookies. It returns a {{jsxref("Promise")}} which resolves when the operation is successful. ## Examples In this example the {{domxref("ServiceWorkerRegistration")}} represented by `registration` is subscribing to change events on the cookie named `"cookie1"` with a scope of `"/path1"`. ```js -const subscriptions = [{ name: "cookie1", url: `/path1` }]; -await registration.cookies.subscribe(subscriptions); +const subscriptions = [{ name: "cookie1", url: "/path1" }]; + +await self.registration.cookies.subscribe(subscriptions); ``` -If the {{domxref("ServiceWorkerRegistration")}} has subscribed to any cookies then {{domxref("CookieStoreManager.getSubscriptions()","getSubscriptions()")}} will return a list of cookies represented by objects in the same format as used for the original subscription. +If the {{domxref("ServiceWorkerRegistration")}} has subscribed to any cookies, then {{domxref("CookieStoreManager.getSubscriptions()","getSubscriptions()")}} will return a list of cookies represented by objects in the same format as used for the original subscription. ```js -const subscriptions = await registration.cookies.getSubscriptions(); +const subscriptions = await self.registration.cookies.getSubscriptions(); ``` ## Specifications diff --git a/files/en-us/web/api/cookiestoremanager/subscribe/index.md b/files/en-us/web/api/cookiestoremanager/subscribe/index.md index c1f3b8acd694038..6bb0456cfde7289 100644 --- a/files/en-us/web/api/cookiestoremanager/subscribe/index.md +++ b/files/en-us/web/api/cookiestoremanager/subscribe/index.md @@ -8,7 +8,7 @@ status: browser-compat: api.CookieStoreManager.subscribe --- -{{securecontext_header}}{{APIRef("Cookie Store")}}{{SeeCompatTable}} +{{securecontext_header}}{{APIRef("Cookie Store API")}}{{SeeCompatTable}}{{AvailableInWorkers}} The **`subscribe()`** method of the {{domxref("CookieStoreManager")}} interface subscribes a {{domxref("ServiceWorkerRegistration")}} to cookie change events. @@ -43,16 +43,26 @@ A {{jsxref("Promise")}} that resolves with {{jsxref("undefined")}} when the subs In this example the {{domxref("ServiceWorkerRegistration")}} represented by `registration` is subscribing to change events on the cookie named `"cookie1"` with a scope of `"/path1"`. ```js -const subscriptions = [{ name: "cookie1", url: `/path1` }]; -await registration.cookies.subscribe(subscriptions); +const subscriptions = [{ name: "cookie1", url: "/path1" }]; + +await self.registration.cookies.subscribe(subscriptions); ``` The URL passed to the `subscribe()` method, may be narrower than the service worker registration scope. In the following example the subscription is for `/path/one/`, so it will receive change events for changes on the first cookie, but not the second. ```js -registration.cookies.subscribe([{ name: "cookie1", url: "/path/one/" }]); // subscription -cookieStore.set({ name: "cookie1", value: "cookie-value", path: "/path/one/" }); // receives a change event -cookieStore.set({ name: "cookie1", value: "cookie-value", path: "/path/two/" }); // does not receive a change event +self.registration.cookies.subscribe([{ name: "cookie1", url: "/path/one/" }]); // subscription + +self.cookieStore.set({ + name: "cookie1", + value: "cookie-value", + path: "/path/one/", +}); // receives a change event +self.cookieStore.set({ + name: "cookie1", + value: "cookie-value", + path: "/path/two/", +}); // does not receive a change event ``` ## Specifications diff --git a/files/en-us/web/api/cookiestoremanager/unsubscribe/index.md b/files/en-us/web/api/cookiestoremanager/unsubscribe/index.md index 5ce849ba2dc1dcd..42669d832755b93 100644 --- a/files/en-us/web/api/cookiestoremanager/unsubscribe/index.md +++ b/files/en-us/web/api/cookiestoremanager/unsubscribe/index.md @@ -8,7 +8,7 @@ status: browser-compat: api.CookieStoreManager.unsubscribe --- -{{securecontext_header}}{{APIRef("Cookie Store")}}{{SeeCompatTable}} +{{securecontext_header}}{{APIRef("Cookie Store API")}}{{SeeCompatTable}}{{AvailableInWorkers}} The **`unsubscribe()`** method of the {{domxref("CookieStoreManager")}} interface stops the {{domxref("ServiceWorkerRegistration")}} from receiving previously subscribed events. @@ -43,8 +43,9 @@ A {{jsxref("Promise")}} that resolves with {{jsxref("undefined")}} when the serv In this example the {{domxref("ServiceWorkerRegistration")}} represented by `registration` is unsubscribing from change events on the cookie named `"cookie1"` with a scope of `"/path1"`. ```js -const subscriptions = [{ name: "cookie1", url: `/path1` }]; -await registration.cookies.unsubscribe(subscriptions); +const subscriptions = [{ name: "cookie1", url: "/path1" }]; + +await self.registration.cookies.unsubscribe(subscriptions); ``` ## Specifications diff --git a/files/en-us/web/api/extendablecookiechangeevent/changed/index.md b/files/en-us/web/api/extendablecookiechangeevent/changed/index.md index 33a5bd5dee64eca..2e8c0a9a4883f95 100644 --- a/files/en-us/web/api/extendablecookiechangeevent/changed/index.md +++ b/files/en-us/web/api/extendablecookiechangeevent/changed/index.md @@ -6,7 +6,7 @@ page-type: web-api-instance-property browser-compat: api.ExtendableCookieChangeEvent.changed --- -{{securecontext_header}}{{APIRef("Cookie Store API")}} +{{securecontext_header}}{{APIRef("Cookie Store API")}}{{AvailableInWorkers}} The **`changed`** read-only property of the {{domxref("ExtendableCookieChangeEvent")}} interface returns any cookies that have been changed by the given `ExtendableCookieChangeEvent` instance. @@ -37,6 +37,9 @@ An array of objects containing the changed cookie(s). Each object contains the f - `"none"` - : Cookies will be sent in all contexts. +- `partitioned` + - : A boolean indicating whether the cookie is a partitioned cookie (`true`) or not (`false`). See [Cookies Having Independent Partitioned State (CHIPS)](/en-US/docs/Web/Privacy/Partitioned_cookies) for more information. + ## Examples In this example when the cookie is set, the event listener logs the `changed` property to the console. The first item in that array contains an object representing the cookie that has just been set. @@ -47,7 +50,8 @@ self.addEventListener("cookiechange", (event) => { }); const one_day = 24 * 60 * 60 * 1000; -cookieStore.set({ + +self.cookieStore.set({ name: "cookie1", value: "cookie1-value", expires: Date.now() + one_day, diff --git a/files/en-us/web/api/extendablecookiechangeevent/deleted/index.md b/files/en-us/web/api/extendablecookiechangeevent/deleted/index.md index fa3d8595dfcc570..8c399667b3a2cd9 100644 --- a/files/en-us/web/api/extendablecookiechangeevent/deleted/index.md +++ b/files/en-us/web/api/extendablecookiechangeevent/deleted/index.md @@ -6,7 +6,7 @@ page-type: web-api-instance-property browser-compat: api.ExtendableCookieChangeEvent.deleted --- -{{securecontext_header}}{{APIRef("Cookie Store API")}} +{{securecontext_header}}{{APIRef("Cookie Store API")}}{{AvailableInWorkers}} The **`deleted`** read-only property of the {{domxref("ExtendableCookieChangeEvent")}} interface returns any cookies that have been deleted by the given `ExtendableCookieChangeEvent` instance. @@ -37,6 +37,9 @@ An array of objects containing the deleted cookie(s). Each object contains the f - `"none"` - : Cookies will be sent in all contexts. +- `partitioned` + - : A boolean indicating whether the cookie is a partitioned cookie (`true`) or not (`false`). See [Cookies Having Independent Partitioned State (CHIPS)](/en-US/docs/Web/Privacy/Partitioned_cookies) for more information. + ## Examples In this example when the cookie is deleted the event listener logs the first item in the `deleted` property to the console. It contains an object representing the cookie that has just been deleted. diff --git a/files/en-us/web/api/extendablecookiechangeevent/extendablecookiechangeevent/index.md b/files/en-us/web/api/extendablecookiechangeevent/extendablecookiechangeevent/index.md index 5dee11fce44c2e3..f56f36338e0e53b 100644 --- a/files/en-us/web/api/extendablecookiechangeevent/extendablecookiechangeevent/index.md +++ b/files/en-us/web/api/extendablecookiechangeevent/extendablecookiechangeevent/index.md @@ -6,10 +6,10 @@ page-type: web-api-constructor browser-compat: api.ExtendableCookieChangeEvent.ExtendableCookieChangeEvent --- -{{securecontext_header}}{{APIRef("Cookie Store API")}} +{{securecontext_header}}{{APIRef("Cookie Store API")}}{{AvailableInWorkers}} The **`ExtendableCookieChangeEvent()`** constructor creates a new {{domxref("ExtendableCookieChangeEvent")}} object -which is the event type passed to {{domxref("ServiceWorkerRegistration/cookiechange_event", "ServiceWorkerRegistration.oncookiechange()")}}. +which is the event type passed to {{domxref("ServiceWorkerGlobalScope/cookiechange_event", "cookiechange")}}. This constructor is called by the browser when a change event occurs. > **Note:** This event constructor is generally not needed for production websites. It's primary use is for tests that require an instance of this event. @@ -28,9 +28,9 @@ new ExtendableCookieChangeEvent(type, options) It is case-sensitive and browsers always set it to `cookiechange`. - `options` {{optional_inline}} - : An object that, _in addition of the properties defined in {{domxref("ExtendableEvent/ExtendableEvent", "ExtendableEvent()")}}_, can have the following properties: - - `changed` + - `changed` {{optional_inline}} - : An array containing a changed cookie. - - `deleted` + - `deleted` {{optional_inline}} - : An array containing a deleted cookie. ### Return value diff --git a/files/en-us/web/api/extendablecookiechangeevent/index.md b/files/en-us/web/api/extendablecookiechangeevent/index.md index b5dfe9cfb5256f7..15a7be00adf84b4 100644 --- a/files/en-us/web/api/extendablecookiechangeevent/index.md +++ b/files/en-us/web/api/extendablecookiechangeevent/index.md @@ -5,9 +5,9 @@ page-type: web-api-interface browser-compat: api.ExtendableCookieChangeEvent --- -{{securecontext_header}}{{APIRef("Cookie Store API")}} +{{securecontext_header}}{{APIRef("Cookie Store API")}}{{AvailableInWorkers}} -The **`ExtendableCookieChangeEvent`** interface of the['Cookie Store API'](/en-US/docs/Web/API/Cookie_Store_API) is the event type passed to {{domxref("ServiceWorkerRegistration.oncookiechange()")}} when any cookie changes occur. A cookie change event consists of a cookie and a type (either "changed" or "deleted".) +The **`ExtendableCookieChangeEvent`** interface of the {{domxref("Cookie Store API", "", "", "nocode")}} is the event type passed to {{domxref("ServiceWorkerGlobalScope.cookiechange_event", "cookiechange")}} event fired at the {{domxref("ServiceWorkerGlobalScope")}} when any cookie changes occur. A cookie change event consists of a cookie and a type (either "changed" or "deleted"). Cookie changes that cause the `ExtendableCookieChangeEvent` to be dispatched are: @@ -33,14 +33,19 @@ _This interface also inherits properties from {{domxref("ExtendableEvent")}}._ - {{domxref("ExtendableCookieChangeEvent.deleted")}} {{ReadOnlyInline}} - : Returns an array containing the deleted cookies. +## Instance methods + +_This interface also inherits methods from {{domxref("ExtendableEvent")}}._ + ## Examples -In the below example we use {{domxref("CookieStoreManager.getSubscriptions()")}} to get a list of existing subscriptions. (In service workers, a subscription is required in order to listen for events.) We unsubscribe from existing subscriptions using {{domxref("CookieStoreManager.unsubscribe()")}}, then subscribe to the cookie with a name of 'COOKIE_NAME' using {{domxref("CookieStoreManager.subscribe()")}}. If that cookie is changed, the event listener logs the event to the console. This will be an `ExtendableCookieChangeEvent` object, with the {{domxref("ExtendableCookieChangeEvent.changed","changed")}} or {{domxref("ExtendableCookieChangeEvent.deleted","deleted")}} property containing the modified cookie. +In the below example, we use {{domxref("CookieStoreManager.getSubscriptions()")}} to get a list of existing subscriptions. (In service workers, a subscription is required in order to listen for events.) We unsubscribe from existing subscriptions using {{domxref("CookieStoreManager.unsubscribe()")}}, then subscribe to the cookie with a name of 'COOKIE_NAME' using {{domxref("CookieStoreManager.subscribe()")}}. If that cookie is changed, the event listener logs the event to the console. This will be an `ExtendableCookieChangeEvent` object, with the {{domxref("ExtendableCookieChangeEvent.changed","changed")}} or {{domxref("ExtendableCookieChangeEvent.deleted","deleted")}} property containing the modified cookie. ```js self.addEventListener("activate", (event) => { event.waitUntil(async () => { const subscriptions = await self.registration.cookies.getSubscriptions(); + await self.registration.cookies.unsubscribe(subscriptions); await self.registration.cookies.subscribe([ diff --git a/files/en-us/web/api/serviceworkerglobalscope/cookiechange_event/index.md b/files/en-us/web/api/serviceworkerglobalscope/cookiechange_event/index.md new file mode 100644 index 000000000000000..d3c277405f2fff7 --- /dev/null +++ b/files/en-us/web/api/serviceworkerglobalscope/cookiechange_event/index.md @@ -0,0 +1,43 @@ +--- +title: "ServiceWorkerGlobalScope: cookiechange event" +short-title: cookiechange +slug: Web/API/ServiceWorkerGlobalScope/cookiechange_event +page-type: web-api-event +status: + - experimental +browser-compat: api.ServiceWorkerGlobalScope.cookiechange_event +--- + +{{APIRef("Cookie Store API")}}{{SeeCompatTable}} + +The **`cookiechange`** event of the {{domxref("ServiceWorkerGlobalScope")}} interface is fired when any cookie changes have occurred which match the Service Worker's cookie change subscription list added via {{domxref("CookieStoreManager.subscribe()")}}. This is part of the {{domxref("Cookie Store API", "", "", "nocode")}}. + +This event is not cancelable and does not bubble. + +## Syntax + +Use the event name in methods like {{domxref("EventTarget.addEventListener", "addEventListener()")}}, or set an event handler property. + +```js +addEventListener("cookiechange", (event) => {}); + +oncookiechange = (event) => {}; +``` + +## Event type + +An {{domxref("ExtendableCookieChangeEvent")}}. Inherits from {{domxref("ExtendableEvent")}}. + +{{InheritanceDiagram("ExtendableCookieChangeEvent")}} + +## Specifications + +{{Specifications}} + +## Browser compatibility + +{{Compat}} + +## See also + +- {{domxref("Cookie Store API", "", "", "nocode")}} diff --git a/files/en-us/web/api/serviceworkerglobalscope/cookiestore/index.md b/files/en-us/web/api/serviceworkerglobalscope/cookiestore/index.md new file mode 100644 index 000000000000000..fccca6d9506fcda --- /dev/null +++ b/files/en-us/web/api/serviceworkerglobalscope/cookiestore/index.md @@ -0,0 +1,29 @@ +--- +title: "ServiceWorkerGlobalScope: cookieStore property" +short-title: cookieStore +slug: Web/API/ServiceWorkerGlobalScope/cookieStore +page-type: web-api-instance-property +status: + - experimental +browser-compat: api.ServiceWorkerGlobalScope.cookieStore +--- + +{{APIRef("Cookie Store API")}}{{SeeCompatTable}} + +The **`cookieStore`** read-only property of the {{domxref("ServiceWorkerGlobalScope")}} interface returns a reference to the {{domxref("CookieStore")}} object associated with the service worker. This is part of the {{domxref("Cookie Store API", "", "", "nocode")}}. + +## Value + +A {{domxref("CookieStore")}} object instance. + +## Specifications + +{{Specifications}} + +## Browser compatibility + +{{Compat}} + +## See also + +- {{domxref("Cookie Store API", "", "", "nocode")}} diff --git a/files/en-us/web/api/serviceworkerglobalscope/index.md b/files/en-us/web/api/serviceworkerglobalscope/index.md index 5199e6f8a9e97fa..0c15abe2d5801b8 100644 --- a/files/en-us/web/api/serviceworkerglobalscope/index.md +++ b/files/en-us/web/api/serviceworkerglobalscope/index.md @@ -25,6 +25,8 @@ _This interface inherits properties from the {{domxref("WorkerGlobalScope")}} in - {{domxref("ServiceWorkerGlobalScope.clients")}} {{ReadOnlyInline}} - : Contains the {{domxref("Clients")}} object associated with the service worker. +- {{domxref("ServiceWorkerGlobalScope.cookieStore")}} {{ReadOnlyInline}} {{Experimental_Inline}} + - : Returns a reference to the {{domxref("CookieStore")}} object associated with the service worker. - {{domxref("ServiceWorkerGlobalScope.registration")}} {{ReadOnlyInline}} - : Contains the {{domxref("ServiceWorkerRegistration")}} object that represents the service worker's registration. @@ -53,6 +55,8 @@ Listen to this event using {{domxref("EventTarget/addEventListener()", "addEvent - : Fired on a payment app's service worker to check whether it is ready to handle a payment. Specifically, it is fired when the merchant website calls {{domxref("PaymentRequest.PaymentRequest", "new PaymentRequest()")}}. - {{domxref("ServiceWorkerGlobalScope/contentdelete_event", "contentdelete")}} {{Experimental_Inline}} - : Occurs when an item is removed from the {{domxref("ContentIndex", "Content Index")}}. +- {{domxref("ServiceWorkerGlobalScope/cookiechange_event", "cookiechange")}} {{Experimental_Inline}} + - : Fired when any cookie changes have occurred which match the Service Worker's cookie change subscription list. - {{domxref("ServiceWorkerGlobalScope/fetch_event", "fetch")}} - : Occurs when a {{domxref("fetch()")}} is called. - {{domxref("ServiceWorkerGlobalScope/install_event", "install")}} diff --git a/files/en-us/web/api/serviceworkerregistration/cookies/index.md b/files/en-us/web/api/serviceworkerregistration/cookies/index.md new file mode 100644 index 000000000000000..7c6950a49189c33 --- /dev/null +++ b/files/en-us/web/api/serviceworkerregistration/cookies/index.md @@ -0,0 +1,29 @@ +--- +title: "ServiceWorkerRegistration: cookies property" +short-title: cookies +slug: Web/API/ServiceWorkerRegistration/cookies +page-type: web-api-instance-property +status: + - experimental +browser-compat: api.ServiceWorkerRegistration.cookies +--- + +{{APIRef("Cookie Store API")}}{{SeeCompatTable}} + +The **`cookies`** read-only property of the {{domxref("ServiceWorkerRegistration")}} interface returns a reference to the {{domxref('CookieStoreManager')}} interface, which allows subscribe and unsubscribe to cookie change events. This is part of the {{domxref("Cookie Store API", "", "", "nocode")}}. + +## Value + +A {{domxref("CookieStoreManager")}} object. + +## Specifications + +{{Specifications}} + +## Browser compatibility + +{{Compat}} + +## See also + +- {{domxref("Cookie Store API", "", "", "nocode")}} diff --git a/files/en-us/web/api/serviceworkerregistration/index.md b/files/en-us/web/api/serviceworkerregistration/index.md index 047b5e7c4b52945..512122598f608ff 100644 --- a/files/en-us/web/api/serviceworkerregistration/index.md +++ b/files/en-us/web/api/serviceworkerregistration/index.md @@ -23,6 +23,8 @@ _Also inherits properties from its parent interface,_ {{domxref("EventTarget")}} - : Returns a service worker whose state is `activating` or `activated`. This is initially set to `null`. An active worker will control a {{domxref("Client")}} if the client's URL falls within the scope of the registration (the `scope` option set when {{domxref("ServiceWorkerContainer.register")}} is first called.) - {{domxref("ServiceWorkerRegistration.backgroundFetch")}} {{ReadOnlyInline}} {{Experimental_Inline}} - : Returns a reference to a {{domxref("BackgroundFetchManager")}} object, which manages background fetch operations. +- {{domxref("ServiceWorkerRegistration.cookies")}} {{ReadOnlyInline}} {{Experimental_Inline}} + - : Returns a reference to the {{domxref('CookieStoreManager')}} interface, which allows subscribe and unsubscribe to cookie change events. - {{domxref("ServiceWorkerRegistration.index")}} {{ReadOnlyInline}} {{Experimental_Inline}} - : Returns a reference to the {{domxref("ContentIndex")}} interface, for managing indexed content for offline viewing. - {{domxref("ServiceWorkerRegistration.installing")}} {{ReadOnlyInline}} diff --git a/files/en-us/web/api/window/cookiestore/index.md b/files/en-us/web/api/window/cookiestore/index.md new file mode 100644 index 000000000000000..60de7b0294fd0da --- /dev/null +++ b/files/en-us/web/api/window/cookiestore/index.md @@ -0,0 +1,29 @@ +--- +title: "Window: cookieStore property" +short-title: cookieStore +slug: Web/API/Window/cookieStore +page-type: web-api-instance-property +status: + - experimental +browser-compat: api.Window.cookieStore +--- + +{{securecontext_header}}{{APIRef("Cookie Store API")}}{{SeeCompatTable}} + +The **`cookieStore`** read-only property of the {{domxref("Window")}} interface returns a reference to the {{domxref("CookieStore")}} object for the current document context. This is part of the {{domxref("Cookie Store API", "", "", "nocode")}}. + +## Value + +A {{domxref("CookieStore")}} object instance. + +## Specifications + +{{Specifications}} + +## Browser compatibility + +{{Compat}} + +## See also + +- {{domxref("Cookie Store API", "", "", "nocode")}} diff --git a/files/en-us/web/api/window/index.md b/files/en-us/web/api/window/index.md index 73f9e30457608ee..c7d2231c0400637 100644 --- a/files/en-us/web/api/window/index.md +++ b/files/en-us/web/api/window/index.md @@ -33,6 +33,8 @@ Note that properties which are objects (e.g., for overriding the prototype of bu - : This property indicates whether the current window is closed or not. - {{domxref("Window.console")}} {{ReadOnlyInline}} - : Returns a reference to the console object which provides access to the browser's debugging console. +- {{domxref("Window.cookieStore")}} {{ReadOnlyInline}} {{Experimental_Inline}} + - : Returns a reference to the {{domxref("CookieStore")}} object for the current document context. - {{domxref("Window.credentialless")}} {{ReadOnlyInline}} {{Experimental_Inline}} - : Returns a boolean that indicates whether the current document was loaded inside a credentialless {{htmlelement("iframe")}}. See [IFrame credentialless](/en-US/docs/Web/Security/IFrame_credentialless) for more details. - {{domxref("crossOriginIsolated", "Window.crossOriginIsolated")}} {{ReadOnlyInline}} diff --git a/files/jsondata/GroupData.json b/files/jsondata/GroupData.json index 0ff0ca6c2336829..7ae07c22c25fb96 100644 --- a/files/jsondata/GroupData.json +++ b/files/jsondata/GroupData.json @@ -193,8 +193,12 @@ "ExtendableCookieChangeEvent" ], "methods": [], - "properties": [], - "events": [] + "properties": [ + "Window.cookieStore", + "ServiceWorkerGlobalScope.cookieStore", + "ServiceWorkerRegistration.cookies" + ], + "events": ["ServiceWorkerGlobalScope: cookiechange event"] }, "Credential Management API": { "overview": ["Credential Management API"],