Skip to content

Adding webdriver cookie commands#44388

Open
Rumyra wants to merge 2 commits into
mdn:mainfrom
Rumyra:cookiecommands
Open

Adding webdriver cookie commands#44388
Rumyra wants to merge 2 commits into
mdn:mainfrom
Rumyra:cookiecommands

Conversation

@Rumyra

@Rumyra Rumyra commented Jun 8, 2026

Copy link
Copy Markdown
Collaborator

Description

This pr adds the WebDriver classic cookie related commands

  • Add cookie
  • Delete all cookies
  • Delete cookie
  • Get all cookies
  • Get named cookie

And updates links in invalidcookiedomain error

Motivation

Filling the gaps in web driver classic documentation

Additional details

I've not added error pages - we plan to work on those separately

Related issues and pull requests

@Rumyra Rumyra requested a review from a team as a code owner June 8, 2026 14:37
@Rumyra Rumyra requested review from chrisdavidmills and dipikabh and removed request for a team and chrisdavidmills June 8, 2026 14:37
@github-actions github-actions Bot added Content:WebDriver WebDriver docs size/m [PR only] 51-500 LoC changed labels Jun 8, 2026

@dipikabh dipikabh left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great, thanks @Rumyra!
The pages are looking solid overall. I've added a few suggestions.

The body is a JSON Object with a single `cookie` field whose value is a **cookie object**:

- `name`
- : The name of the cookie. Required.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Required." can be removed from everywhere


### Payload

The body is a JSON Object with a single `cookie` field whose value is a **cookie object**:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The body is a JSON Object with a single `cookie` field whose value is a **cookie object**:
The input is a JSON object with a single `cookie` key whose value is a cookie object with the following fields:

- `httpOnly` {{optional_inline}}
- : Whether the cookie is an HTTP-only cookie. Defaults to `false`.
- `expiry` {{optional_inline}}
- : When the cookie expires, specified in seconds since the Unix epoch. Must be a number in the 0 to 2^53 − 1 range. If omitted, the cookie is a session cookie.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"is a session cookie" -> "is treated as a session cookie"?

Suggested change
- : When the cookie expires, specified in seconds since the Unix epoch. Must be a number in the 0 to 2^53 − 1 range. If omitted, the cookie is a session cookie.
- : The cookie's expiry time in seconds since the Unix epoch. This value must be a number in the 0 to 2^53 − 1 range. If omitted, the cookie is treated as a session cookie.

- `expiry` {{optional_inline}}
- : When the cookie expires, specified in seconds since the Unix epoch. Must be a number in the 0 to 2^53 − 1 range. If omitted, the cookie is a session cookie.
- `sameSite` {{optional_inline}}
- : The cookie's [same-site policy](/en-US/docs/Web/HTTP/Reference/Headers/Set-Cookie#samesitesamesite-value). One of `"Lax"`, `"Strict"`, or `"None"`.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Changes here can also be replicated to getnamedcookie file
  • Is there a default value here?
Suggested change
- : The cookie's [same-site policy](/en-US/docs/Web/HTTP/Reference/Headers/Set-Cookie#samesitesamesite-value). One of `"Lax"`, `"Strict"`, or `"None"`.
- : The cookie's [same-site policy](/en-US/docs/Web/HTTP/Reference/Headers/Set-Cookie#samesitesamesite-value). Possible values include`"Lax"`, `"Strict"`, and `"None"`.

### Errors

- [`Invalid argument`](/en-US/docs/Web/WebDriver/Reference/Errors/InvalidArgument)
- : The `cookie` object is missing, is not a JSON Object, is missing a required field, or one of its fields does not meet the type or value constraints.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- : The `cookie` object is missing, is not a JSON Object, is missing a required field, or one of its fields does not meet the type or value constraints.
- : The `cookie` object is missing, is not a JSON object, is missing a required field, or one of its fields does not meet the type or value constraints.


### Return value

A single **cookie object** with the following fields:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
A single **cookie object** with the following fields:
A single cookie object with the following fields:

Comment on lines +41 to +44
- `expiry`
- : When the cookie expires, specified in seconds since the Unix epoch. Omitted for session cookies.
- `sameSite`
- : The cookie's [same-site policy](/en-US/docs/Web/HTTP/Reference/Headers/Set-Cookie#samesitesamesite-value). One of `"Lax"`, `"Strict"`, or `"None"`.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment as in addcookie

- `Unexpected alert open`
- : A user prompt, such as [`window.alert`](/en-US/docs/Web/API/Window/alert), blocks execution of the command until it is dealt with.
- [`Invalid session id`](/en-US/docs/Web/WebDriver/Reference/Errors/InvalidSessionID)
- : Session does not exist.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- : Session does not exist.
- : The specified session does not exist.

Comment on lines +39 to +42
- `expiry`
- : When the cookie expires, specified in seconds since the Unix epoch. Omitted for session cookies.
- `sameSite`
- : The cookie's [same-site policy](/en-US/docs/Web/HTTP/Reference/Headers/Set-Cookie#samesitesamesite-value). One of `"Lax"`, `"Strict"`, or `"None"`.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as in addcookie

```bash
curl -i -H "Content-Type: application/json" \
-d '{"cookie": {"name": "session_token", "value": "abc123", "secure": true, "sameSite": "Strict"}}' \
http://localhost:4444/session/ID/cookie

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In all such examples, we must replace ID with a realistic ID value.

I notice that I should similarly update the examples in Back and Forward commands!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Content:WebDriver WebDriver docs size/m [PR only] 51-500 LoC changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants