# Cypress Documentation
# Source: https://raw.githubusercontent.com/cypress-io/cypress-documentation/main/docs/api/commands/getcookies.mdx
# Path: docs/api/commands/getcookies.mdx

---
title: 'getCookies | Cypress Documentation'
description: Get browser cookies for the current domain or the specified domain in Cypress.
sidebar_label: getCookies
---

<ProductHeading product="app" />

# getCookies

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

## Syntax

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

### Usage

<Icon name="check-circle" color="green" /> **Correct Usage**

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

### Arguments

<Icon name="angle-right" /> **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](/app/core-concepts/open-mode#Command-Log) |
| `timeout` | [`responseTimeout`](/app/references/configuration#Timeouts) | Time to wait for `cy.getCookies()` to resolve before [timing out](#Timeouts)        |

<HeaderYields />

`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.

```javascript
// assume we just logged in
cy.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')
  })
```

## Rules

<HeaderRequirements />

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

<HeaderAssertions />

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

<HeaderTimeouts />

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

:::caution

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_**

```javascript
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:

<DocsImage
  src="/img/api/getcookies/get-browser-cookies-and-inspect-all-properties.png"
  alt="Command Log getcookies"
/>

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

<DocsImage
  src="/img/api/getcookies/test-application-cookies.png"
  alt="Console Log getcookies"
/>

## History

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

## See also

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