{
  "doc": {
    "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": "/llm/markdown/api/commands/getcookies.md",
    "version": "29f95bf8bb06f320986f3749f5bf09a35a409eab",
    "updated_at": "2026-09-04T10:49:54.630Z",
    "headings": [
      {
        "id": "api/commands/getcookies#getcookies",
        "text": "getCookies",
        "level": 1
      },
      {
        "id": "api/commands/getcookies#syntax",
        "text": "Syntax",
        "level": 2
      },
      {
        "id": "api/commands/getcookies#usage",
        "text": "Usage",
        "level": 3
      },
      {
        "id": "api/commands/getcookies#arguments",
        "text": "Arguments",
        "level": 3
      },
      {
        "id": "api/commands/getcookies#yields",
        "text": "Yields",
        "level": 3
      },
      {
        "id": "api/commands/getcookies#when-no-matching-cookies-are-present",
        "text": "When no matching cookies are present:",
        "level": 4
      },
      {
        "id": "api/commands/getcookies#examples",
        "text": "Examples",
        "level": 2
      },
      {
        "id": "api/commands/getcookies#get-cookies",
        "text": "Get Cookies",
        "level": 3
      },
      {
        "id": "api/commands/getcookies#get-cookies-after-logging-in",
        "text": "Get cookies after logging in",
        "level": 4
      },
      {
        "id": "api/commands/getcookies#forward-the-session-to-another-destination",
        "text": "Forward the session to another destination",
        "level": 4
      },
      {
        "id": "api/commands/getcookies#rules",
        "text": "Rules",
        "level": 2
      },
      {
        "id": "api/commands/getcookies#requirements",
        "text": "Requirements",
        "level": 3
      },
      {
        "id": "api/commands/getcookies#assertions",
        "text": "Assertions",
        "level": 3
      },
      {
        "id": "api/commands/getcookies#timeouts",
        "text": "Timeouts",
        "level": 3
      },
      {
        "id": "api/commands/getcookies#command-log",
        "text": "Command Log",
        "level": 2
      },
      {
        "id": "api/commands/getcookies#history",
        "text": "History",
        "level": 2
      },
      {
        "id": "api/commands/getcookies#see-also",
        "text": "See also",
        "level": 2
      }
    ]
  },
  "chunks": [
    {
      "id": "api/commands/getcookies#syntax",
      "doc_id": "api/commands/getcookies",
      "heading": "Syntax",
      "heading_level": 2,
      "content_markdown": "## Syntax\n\n```\ncy.getCookies()\ncy.getCookies(options)\n```\n\n### Usage\n\n**Correct Usage**\n\n```\ncy.getCookies() // Get cookies for the currrent domain\n```\n\n### Arguments\n\n**options _(Object)_**\n\nPass in an options object to change the default behavior of `cy.getCookies()`.\n\n| Option | Default | Description |\n| --- | --- | --- |\n| `domain` | Hostname of the current URL | Retrieves the cookies from the specified domain |\n| `log` | `true` | Displays the command in the [Command log](/llm/markdown/app/core-concepts/open-mode.md#Command-Log) |\n| `timeout` | [`defaultCommandTimeout`](/llm/markdown/app/references/configuration.md#Timeouts) | Time to wait for `cy.getCookies()` to resolve before [timing out](#Timeouts) |\n\n### Yields\n\n`cy.getCookies()` yields an array of cookie objects. Each cookie object has the following properties:\n\n*   `domain`: _(String)_\n*   `expiry`: _(Number)_ _(if specified)_\n*   `hostOnly`: _(Boolean)_ _(if specified)_\n*   `httpOnly`: _(Boolean)_\n*   `name`: _(String)_\n*   `path`: _(String)_\n*   `sameSite`: _(String)_ _(if specified)_\n*   `secure`: _(Boolean)_\n*   `value`: _(String)_\n\n`cy.getCookies()` is a query, and it is _safe_ to chain further commands. It will automatically [retry](/llm/markdown/app/core-concepts/retry-ability.md) until all chained assertions have passed, or until it times out, re-querying the list of cookies on each retry so the yielded array stays up to date.\n\nBecause `cy.getCookies()` is a query, it re-reads the cookies on every retry, and assertions you chain with [`.should()`](/llm/markdown/api/commands/should.md) drive those retries until they pass or the command times out. A [`.then()`](/llm/markdown/api/commands/then.md) callback, by contrast, runs only once after the command settles and is not retried — so prefer chaining [`.should()`](/llm/markdown/api/commands/should.md) assertions over asserting inside `.then()` when you need Cypress to wait for the cookies to be set.\n\n#### When no matching cookies are present:\n\nOn each read, `cy.getCookies()` yields the current array of cookie objects, or an empty array if none exist yet. The yielded array is the subject your chained assertions run against. If an assertion fails, because the array is empty, or because its contents don't match yet, the query re-reads the cookies and re-runs the assertion, looping until it passes or the command times out.\n",
      "section": "api",
      "anchors": [
        "syntax"
      ],
      "path": "/llm/json/chunked/api/commands/getcookies.json",
      "token_estimate": 435
    },
    {
      "id": "api/commands/getcookies#arguments",
      "doc_id": "api/commands/getcookies",
      "heading": "Arguments",
      "heading_level": 3,
      "content_markdown": "### Arguments\n\n**options _(Object)_**\n\nPass in an options object to change the default behavior of `cy.getCookies()`.\n\n| Option | Default | Description |\n| --- | --- | --- |\n| `domain` | Hostname of the current URL | Retrieves the cookies from the specified domain |\n| `log` | `true` | Displays the command in the [Command log](/llm/markdown/app/core-concepts/open-mode.md#Command-Log) |\n| `timeout` | [`defaultCommandTimeout`](/llm/markdown/app/references/configuration.md#Timeouts) | Time to wait for `cy.getCookies()` to resolve before [timing out](#Timeouts) |\n",
      "section": "api",
      "anchors": [
        "arguments"
      ],
      "path": "/llm/json/chunked/api/commands/getcookies.json",
      "token_estimate": 101
    },
    {
      "id": "api/commands/getcookies#yields",
      "doc_id": "api/commands/getcookies",
      "heading": "Yields",
      "heading_level": 3,
      "content_markdown": "### Yields\n\n`cy.getCookies()` yields an array of cookie objects. Each cookie object has the following properties:\n\n*   `domain`: _(String)_\n*   `expiry`: _(Number)_ _(if specified)_\n*   `hostOnly`: _(Boolean)_ _(if specified)_\n*   `httpOnly`: _(Boolean)_\n*   `name`: _(String)_\n*   `path`: _(String)_\n*   `sameSite`: _(String)_ _(if specified)_\n*   `secure`: _(Boolean)_\n*   `value`: _(String)_\n\n`cy.getCookies()` is a query, and it is _safe_ to chain further commands. It will automatically [retry](/llm/markdown/app/core-concepts/retry-ability.md) until all chained assertions have passed, or until it times out, re-querying the list of cookies on each retry so the yielded array stays up to date.\n\nBecause `cy.getCookies()` is a query, it re-reads the cookies on every retry, and assertions you chain with [`.should()`](/llm/markdown/api/commands/should.md) drive those retries until they pass or the command times out. A [`.then()`](/llm/markdown/api/commands/then.md) callback, by contrast, runs only once after the command settles and is not retried — so prefer chaining [`.should()`](/llm/markdown/api/commands/should.md) assertions over asserting inside `.then()` when you need Cypress to wait for the cookies to be set.\n\n#### When no matching cookies are present:\n\nOn each read, `cy.getCookies()` yields the current array of cookie objects, or an empty array if none exist yet. The yielded array is the subject your chained assertions run against. If an assertion fails, because the array is empty, or because its contents don't match yet, the query re-reads the cookies and re-runs the assertion, looping until it passes or the command times out.\n",
      "section": "api",
      "anchors": [
        "yields"
      ],
      "path": "/llm/json/chunked/api/commands/getcookies.json",
      "token_estimate": 307
    },
    {
      "id": "api/commands/getcookies#when-no-matching-cookies-are-present",
      "doc_id": "api/commands/getcookies",
      "heading": "When no matching cookies are present:",
      "heading_level": 4,
      "content_markdown": "#### When no matching cookies are present:\n\nOn each read, `cy.getCookies()` yields the current array of cookie objects, or an empty array if none exist yet. The yielded array is the subject your chained assertions run against. If an assertion fails, because the array is empty, or because its contents don't match yet, the query re-reads the cookies and re-runs the assertion, looping until it passes or the command times out.\n",
      "section": "api",
      "anchors": [
        "when-no-matching-cookies-are-present"
      ],
      "path": "/llm/json/chunked/api/commands/getcookies.json",
      "token_estimate": 95
    },
    {
      "id": "api/commands/getcookies#examples",
      "doc_id": "api/commands/getcookies",
      "heading": "Examples",
      "heading_level": 2,
      "content_markdown": "## Examples\n\n### Get Cookies\n\n#### Get cookies after logging in\n\nIn this example, on first login our server sends us back a session cookie.\n\n```\n// assume we just logged in\ncy.contains('Login').click()\ncy.url().should('include', 'profile')\ncy.getCookies()\n  .should('have.length', 1)\n  .then((cookies) => {\n    expect(cookies[0]).to.have.property('name', 'session_id')\n  })\n```\n\n#### Forward the session to another destination\n\n[`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:\n\n*   a **different domain** (`cy.request()` only sends cookies that match the request URL)\n*   something **outside the browser**, like a [`cy.task()`](/llm/markdown/api/commands/task.md) or an external HTTP client\n\nIn those cases, combine the cookies into a single `Cookie` header string:\n\n```\ncy.getCookies().then((cookies) => {\n  const cookieHeader = cookies.map((c) => `${c.name}=${c.value}`).join('; ')\n\n  cy.request({\n    url: 'https://api.other-service.com/protected',\n    headers: {\n      Cookie: cookieHeader,\n    },\n  })\n})\n```\n",
      "section": "api",
      "anchors": [
        "examples"
      ],
      "path": "/llm/json/chunked/api/commands/getcookies.json",
      "token_estimate": 215
    },
    {
      "id": "api/commands/getcookies#get-cookies",
      "doc_id": "api/commands/getcookies",
      "heading": "Get Cookies",
      "heading_level": 3,
      "content_markdown": "### Get Cookies\n\n#### Get cookies after logging in\n\nIn this example, on first login our server sends us back a session cookie.\n\n```\n// assume we just logged in\ncy.contains('Login').click()\ncy.url().should('include', 'profile')\ncy.getCookies()\n  .should('have.length', 1)\n  .then((cookies) => {\n    expect(cookies[0]).to.have.property('name', 'session_id')\n  })\n```\n\n#### Forward the session to another destination\n\n[`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:\n\n*   a **different domain** (`cy.request()` only sends cookies that match the request URL)\n*   something **outside the browser**, like a [`cy.task()`](/llm/markdown/api/commands/task.md) or an external HTTP client\n\nIn those cases, combine the cookies into a single `Cookie` header string:\n\n```\ncy.getCookies().then((cookies) => {\n  const cookieHeader = cookies.map((c) => `${c.name}=${c.value}`).join('; ')\n\n  cy.request({\n    url: 'https://api.other-service.com/protected',\n    headers: {\n      Cookie: cookieHeader,\n    },\n  })\n})\n```\n",
      "section": "api",
      "anchors": [
        "get-cookies"
      ],
      "path": "/llm/json/chunked/api/commands/getcookies.json",
      "token_estimate": 212
    },
    {
      "id": "api/commands/getcookies#get-cookies-after-logging-in",
      "doc_id": "api/commands/getcookies",
      "heading": "Get cookies after logging in",
      "heading_level": 4,
      "content_markdown": "#### Get cookies after logging in\n\nIn this example, on first login our server sends us back a session cookie.\n\n```\n// assume we just logged in\ncy.contains('Login').click()\ncy.url().should('include', 'profile')\ncy.getCookies()\n  .should('have.length', 1)\n  .then((cookies) => {\n    expect(cookies[0]).to.have.property('name', 'session_id')\n  })\n```\n",
      "section": "api",
      "anchors": [
        "get-cookies-after-logging-in"
      ],
      "path": "/llm/json/chunked/api/commands/getcookies.json",
      "token_estimate": 53
    },
    {
      "id": "api/commands/getcookies#forward-the-session-to-another-destination",
      "doc_id": "api/commands/getcookies",
      "heading": "Forward the session to another destination",
      "heading_level": 4,
      "content_markdown": "#### Forward the session to another destination\n\n[`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:\n\n*   a **different domain** (`cy.request()` only sends cookies that match the request URL)\n*   something **outside the browser**, like a [`cy.task()`](/llm/markdown/api/commands/task.md) or an external HTTP client\n\nIn those cases, combine the cookies into a single `Cookie` header string:\n\n```\ncy.getCookies().then((cookies) => {\n  const cookieHeader = cookies.map((c) => `${c.name}=${c.value}`).join('; ')\n\n  cy.request({\n    url: 'https://api.other-service.com/protected',\n    headers: {\n      Cookie: cookieHeader,\n    },\n  })\n})\n```\n",
      "section": "api",
      "anchors": [
        "forward-the-session-to-another-destination"
      ],
      "path": "/llm/json/chunked/api/commands/getcookies.json",
      "token_estimate": 155
    },
    {
      "id": "api/commands/getcookies#rules",
      "doc_id": "api/commands/getcookies",
      "heading": "Rules",
      "heading_level": 2,
      "content_markdown": "## Rules\n\n### Requirements\n\n*   `cy.getCookies()` requires being chained off of `cy`.\n\n### Assertions\n\n*   `cy.getCookies()` will automatically [retry](/llm/markdown/app/core-concepts/retry-ability.md) until all chained assertions have passed.\n\n### Timeouts\n\n*   `cy.getCookies()` can time out waiting for assertions you've added to pass.\n",
      "section": "api",
      "anchors": [
        "rules"
      ],
      "path": "/llm/json/chunked/api/commands/getcookies.json",
      "token_estimate": 52
    },
    {
      "id": "api/commands/getcookies#command-log",
      "doc_id": "api/commands/getcookies",
      "heading": "Command Log",
      "heading_level": 2,
      "content_markdown": "## Command Log\n\n**_Get browser cookies and inspect all properties_**\n\n```\ncy.getCookies()\n  .should('have.length', 1)\n  .then((cookies) => {\n    expect(cookies[0]).to.have.property('name', 'fakeCookie1')\n    expect(cookies[0]).to.have.property('value', '123ABC')\n    expect(cookies[0]).to.have.property('domain')\n    expect(cookies[0]).to.have.property('httpOnly')\n    expect(cookies[0]).to.have.property('path')\n    expect(cookies[0]).to.have.property('secure')\n  })\n```\n\nThe commands above will display in the Command Log as:\n\nWhen clicking on `getCookies` within the command log, the console outputs the following:\n",
      "section": "api",
      "anchors": [
        "command-log"
      ],
      "path": "/llm/json/chunked/api/commands/getcookies.json",
      "token_estimate": 67
    },
    {
      "id": "api/commands/getcookies#history",
      "doc_id": "api/commands/getcookies",
      "heading": "History",
      "heading_level": 2,
      "content_markdown": "## History\n\n| Version | Changes |\n| --- | --- |\n| [16.0.0](/llm/markdown/app/references/changelog.md#16-0-0) | `cy.getCookies()` is now a query and retries assertions until they pass or time out. |\n| [5.0.0](/llm/markdown/app/references/changelog.md#5-0-0) | Removed `experimentalGetCookiesSameSite` and made `sameSite` property always available. |\n| [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`. |\n",
      "section": "api",
      "anchors": [
        "history"
      ],
      "path": "/llm/json/chunked/api/commands/getcookies.json",
      "token_estimate": 75
    }
  ]
}