Skip to content

Commit

Permalink
CookieChangeEvent | add partitioned option & add optional for param…
Browse files Browse the repository at this point in the history
… & fix event name (#31272)

* add partitioned key

* add Optional_Inline mark

* fix event name

* add Instance methods section

* update
  • Loading branch information
skyclouds2001 authored Dec 25, 2023
1 parent c1c96d7 commit 4a4798e
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 11 deletions.
7 changes: 5 additions & 2 deletions files/en-us/web/api/cookiechangeevent/changed/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand All @@ -39,9 +39,12 @@ 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) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 of the {{domxref("CookieStore/change_event", "change")}} event fired at a {{domxref("CookieStore")}} when any cookie changes occur.
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.
Expand All @@ -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
Expand Down
7 changes: 5 additions & 2 deletions files/en-us/web/api/cookiechangeevent/deleted/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand All @@ -39,9 +39,12 @@ 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) => {
Expand Down
8 changes: 6 additions & 2 deletions files/en-us/web/api/cookiechangeevent/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 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").

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.
Expand All @@ -35,6 +35,10 @@ _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.
Expand Down

0 comments on commit 4a4798e

Please sign in to comment.