---
id: api/commands/getcookies
title: cy.getCookies()
description: Get browser cookies for the current domain or the specified domain in Cypress.
section: api
source_path: docs/api/commands/getcookies.mdx
version: fbc9225067c51c52ee13224e3b702cf8a025ec12
updated_at: '2026-08-14T12:36:26.878Z'
---
# getCookies

Get browser cookies for the current domain or the specified domain.

## Syntax

```
cy.getCookies()cy.getCookies(options)
```

### Usage

**Correct Usage**

```
cy.getCookies() // Get cookies for the currrent domain
```

### Arguments

**options _(Object)_**

Pass in an options object to change the default behavior of `cy.getCookies()`.

| Option | Default | Description |
| --- | --- | --- |
| `domain` | Hostname of the current URL | Retrieves the cookies from the specified domain |
| `log` | `true` | Displays the command in the [Command log](/llm/markdown/app/core-concepts/open-mode.md#Command-Log) |
| `timeout` | [`responseTimeout`](/llm/markdown/app/references/configuration.md#Timeouts) | Time to wait for `cy.getCookies()` to resolve before [timing out](#Timeouts) |

### Yields

`cy.getCookies()` yields an array of cookie objects. Each cookie object has the following properties:

*   `domain`: _(String)_
*   `expiry`: _(Number)_ _(if specified)_
*   `hostOnly`: _(Boolean)_ _(if specified)_
*   `httpOnly`: _(Boolean)_
*   `name`: _(String)_
*   `path`: _(String)_
*   `sameSite`: _(String)_ _(if specified)_
*   `secure`: _(Boolean)_
*   `value`: _(String)_

`cy.getCookies()` is not a query. It will not update the returned list if further cookies are added after it initially executes.

## Examples

### Get Cookies

#### Get cookies after logging in

In this example, on first login our server sends us back a session cookie.

```
// assume we just logged incy.contains('Login').click()cy.url().should('include', 'profile')cy.getCookies()  .should('have.length', 1)  .then((cookies) => {    expect(cookies[0]).to.have.property('name', 'session_id')  })
```

#### Forward the session to another destination

[`cy.request()`](/llm/markdown/api/commands/request.md) already sends the browser's cookies for the request URL automatically, so you don't need to build a `Cookie` header to call your own logged-in API. Reach for this pattern only when you need to forward the current session somewhere Cypress won't attach cookies on its own, such as:

*   a **different domain** (`cy.request()` only sends cookies that match the request URL)
*   something **outside the browser**, like a [`cy.task()`](/llm/markdown/api/commands/task.md), [`cy.exec()`](/llm/markdown/api/commands/exec.md), or an external HTTP client

In those cases, combine the cookies into a single `Cookie` header string:

```
cy.getCookies().then((cookies) => {  const cookieHeader = cookies.map((c) => `${c.name}=${c.value}`).join('; ')  cy.request({    url: 'https://api.other-service.com/protected',    headers: {      Cookie: cookieHeader,    },  })})
```

## Rules

### Requirements

*   `cy.getCookies()` requires being chained off of `cy`.

### Assertions

*   `cy.getCookies()` will only run assertions you have chained once, and will not [retry](/llm/markdown/app/core-concepts/retry-ability.md).

### Timeouts

*   `cy.getCookies()` should never time out.

Because `cy.getCookies()` is asynchronous it is technically possible for there to be a timeout while talking to the internal Cypress automation APIs. But for practical purposes it should never happen.

## Command Log

**_Get browser cookies and inspect all properties_**

```
cy.getCookies()  .should('have.length', 1)  .then((cookies) => {    expect(cookies[0]).to.have.property('name', 'fakeCookie1')    expect(cookies[0]).to.have.property('value', '123ABC')    expect(cookies[0]).to.have.property('domain')    expect(cookies[0]).to.have.property('httpOnly')    expect(cookies[0]).to.have.property('path')    expect(cookies[0]).to.have.property('secure')  })
```

The commands above will display in the Command Log as:

When clicking on `getCookies` within the command log, the console outputs the following:

## History

| Version | Changes |
| --- | --- |
| [5.0.0](/llm/markdown/app/references/changelog.md#5-0-0) | Removed `experimentalGetCookiesSameSite` and made `sameSite` property always available. |
| [4.3.0](/llm/markdown/app/references/changelog.md#4-3-0) | Added `sameSite` property when the [experimentalGetCookiesSameSite](/llm/markdown/app/references/configuration.md#Experiments) configuration value is `true`. |

## See also

*   [`cy.clearCookie()`](/llm/markdown/api/commands/clearcookie.md)
*   [`cy.clearCookies()`](/llm/markdown/api/commands/clearcookies.md)
*   [`cy.getCookie()`](/llm/markdown/api/commands/getcookie.md)
*   [`cy.setCookie()`](/llm/markdown/api/commands/setcookie.md)
*   [`Cypress.Cookies.debug()`](/llm/markdown/api/cypress-api/cookies.md)
