{
  "doc": {
    "id": "api/commands/getcookie",
    "title": "cy.getCookie()",
    "description": "Get a browser cookie by its name in Cypress.",
    "section": "api",
    "source_path": "/llm/markdown/api/commands/getcookie.md",
    "version": "5a232a3cf094b8f928b1179ce5af6a5046296fac",
    "updated_at": "2026-11-13T01:14:31.437Z",
    "headings": [
      {
        "id": "api/commands/getcookie#getcookie",
        "text": "getCookie",
        "level": 1
      },
      {
        "id": "api/commands/getcookie#syntax",
        "text": "Syntax",
        "level": 2
      },
      {
        "id": "api/commands/getcookie#usage",
        "text": "Usage",
        "level": 3
      },
      {
        "id": "api/commands/getcookie#arguments",
        "text": "Arguments",
        "level": 3
      },
      {
        "id": "api/commands/getcookie#yields",
        "text": "Yields",
        "level": 3
      },
      {
        "id": "api/commands/getcookie#when-a-cookie-matching-the-name-could-not-be-found",
        "text": "When a cookie matching the name could not be found:",
        "level": 4
      },
      {
        "id": "api/commands/getcookie#examples",
        "text": "Examples",
        "level": 2
      },
      {
        "id": "api/commands/getcookie#session-id",
        "text": "Session id",
        "level": 3
      },
      {
        "id": "api/commands/getcookie#get-session-id-cookie-after-logging-in",
        "text": "Get session_id cookie after logging in",
        "level": 4
      },
      {
        "id": "api/commands/getcookie#send-the-session-cookies-value-in-a-request-header",
        "text": "Send the session cookie's value in a request header",
        "level": 4
      },
      {
        "id": "api/commands/getcookie#check-that-the-session-cookie-is-removed-after-logout",
        "text": "Check that the session cookie is removed after logout",
        "level": 4
      },
      {
        "id": "api/commands/getcookie#assert-on-cookie-properties-from-cy-getcookie",
        "text": "Assert on cookie properties from cy.getCookie()",
        "level": 3
      },
      {
        "id": "api/commands/getcookie#assert-on-one-cookie-property-with-its",
        "text": "Assert on one cookie property with .its()",
        "level": 4
      },
      {
        "id": "api/commands/getcookie#check-the-security-attributes-of-an-auth-cookie",
        "text": "Check the security attributes of an auth cookie",
        "level": 4
      },
      {
        "id": "api/commands/getcookie#check-that-a-remember-me-cookie-expires-in-the-future",
        "text": "Check that a remember-me cookie expires in the future",
        "level": 4
      },
      {
        "id": "api/commands/getcookie#read-a-cookie-on-another-domain-with-cy-getcookie",
        "text": "Read a cookie on another domain with cy.getCookie()",
        "level": 3
      },
      {
        "id": "api/commands/getcookie#get-a-cookie-set-on-a-sibling-api-domain-with-domain",
        "text": "Get a cookie set on a sibling API domain with domain",
        "level": 4
      },
      {
        "id": "api/commands/getcookie#validate-a-cy-session-login-with-cy-getcookie",
        "text": "Validate a cy.session() login with cy.getCookie()",
        "level": 3
      },
      {
        "id": "api/commands/getcookie#check-the-login-cookie-in-a-cy-session-validate-function",
        "text": "Check the login cookie in a cy.session() validate function",
        "level": 4
      },
      {
        "id": "api/commands/getcookie#notes",
        "text": "Notes",
        "level": 2
      },
      {
        "id": "api/commands/getcookie#default-cookie-domain-before-visiting-a-page",
        "text": "Default cookie domain before visiting a page",
        "level": 3
      },
      {
        "id": "api/commands/getcookie#which-cookies-cy-getcookie-matches-by-domain",
        "text": "Which cookies cy.getCookie() matches by domain",
        "level": 3
      },
      {
        "id": "api/commands/getcookie#reading-httponly-cookies-with-cy-getcookie",
        "text": "Reading HttpOnly cookies with cy.getCookie()",
        "level": 3
      },
      {
        "id": "api/commands/getcookie#why-cy-getcookie-yields-null",
        "text": "Why cy.getCookie() yields null",
        "level": 3
      },
      {
        "id": "api/commands/getcookie#rules",
        "text": "Rules",
        "level": 2
      },
      {
        "id": "api/commands/getcookie#requirements",
        "text": "Requirements",
        "level": 3
      },
      {
        "id": "api/commands/getcookie#assertions",
        "text": "Assertions",
        "level": 3
      },
      {
        "id": "api/commands/getcookie#timeouts",
        "text": "Timeouts",
        "level": 3
      },
      {
        "id": "api/commands/getcookie#command-log",
        "text": "Command Log",
        "level": 2
      },
      {
        "id": "api/commands/getcookie#history",
        "text": "History",
        "level": 2
      },
      {
        "id": "api/commands/getcookie#see-also",
        "text": "See also",
        "level": 2
      }
    ]
  },
  "content": {
    "type": "root",
    "children": [
      {
        "type": "heading",
        "depth": 1,
        "children": [
          {
            "type": "text",
            "value": "getCookie"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Get a browser cookie by its name."
          }
        ]
      },
      {
        "type": "heading",
        "depth": 2,
        "children": [
          {
            "type": "text",
            "value": "Syntax"
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "cy.getCookie(name)\ncy.getCookie(name, options)"
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Usage"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Correct Usage"
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "cy.getCookie('auth_key') // Get cookie with name 'auth_key'"
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Incorrect Usage"
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "cy.getCookie() // Errors, a cookie name is required\ncy.getCookie({ domain: 'example.com' }) // Errors, name must be a string"
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Arguments"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "name (String)"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "The name of the cookie to get. Required, and must be a string."
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "options (Object)"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Pass in an options object to change the default behavior of `cy.getCookie()`."
          }
        ]
      },
      {
        "type": "table",
        "align": [
          null,
          null,
          null
        ],
        "children": [
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Option"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Default"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Description"
                  }
                ]
              }
            ]
          },
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "`domain`"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Hostname of the application under test"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Retrieves the cookie from the specified domain"
                  }
                ]
              }
            ]
          },
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "`log`"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "`true`"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Displays the command in the "
                  },
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/app/core-concepts/open-mode.md#Command-Log",
                    "children": [
                      {
                        "type": "text",
                        "value": "Command log"
                      }
                    ]
                  }
                ]
              }
            ]
          },
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "`timeout`"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/app/references/configuration.md#Timeouts",
                    "children": [
                      {
                        "type": "text",
                        "value": "`defaultCommandTimeout`"
                      }
                    ]
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Time to wait for `cy.getCookie()` to resolve before "
                  },
                  {
                    "type": "link",
                    "title": null,
                    "url": "#Timeouts",
                    "children": [
                      {
                        "type": "text",
                        "value": "timing out"
                      }
                    ]
                  }
                ]
              }
            ]
          }
        ]
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Yields"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "`cy.getCookie()` yields a cookie object with the following properties:"
          }
        ]
      },
      {
        "type": "list",
        "ordered": false,
        "start": null,
        "spread": false,
        "children": [
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "`domain`: (String)"
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "`expiry`: (Number) (if specified)"
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "`hostOnly`: (Boolean) (not always reported)"
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "`httpOnly`: (Boolean)"
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "`name`: (String)"
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "`path`: (String)"
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "`sameSite`: (String) (if specified)"
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "`secure`: (Boolean)"
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "`value`: (String)"
                  }
                ]
              }
            ]
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "`cy.getCookie()` is a query, and it is safe to chain further commands. It re-reads the cookie on each "
          },
          {
            "type": "link",
            "title": null,
            "url": "/llm/markdown/app/core-concepts/retry-ability.md",
            "children": [
              {
                "type": "text",
                "value": "retry"
              }
            ]
          },
          {
            "type": "text",
            "value": ", and the assertions you chain with "
          },
          {
            "type": "link",
            "title": null,
            "url": "/llm/markdown/api/commands/should.md",
            "children": [
              {
                "type": "text",
                "value": "`.should()`"
              }
            ]
          },
          {
            "type": "text",
            "value": " drive those retries. If an assertion fails, because the cookie is `null` or because a property doesn't match yet, the query reads the cookie again and re-runs the assertion until it passes or the command times out."
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "With no assertion chained, `cy.getCookie()` yields whatever it reads on the first attempt. A "
          },
          {
            "type": "link",
            "title": null,
            "url": "/llm/markdown/api/commands/then.md",
            "children": [
              {
                "type": "text",
                "value": "`.then()`"
              }
            ]
          },
          {
            "type": "text",
            "value": " callback runs once and isn't retried, so chain `.should('exist')` before it to wait for a cookie that your application sets asynchronously."
          }
        ]
      },
      {
        "type": "heading",
        "depth": 4,
        "children": [
          {
            "type": "text",
            "value": "When a cookie matching the name could not be found:"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "`cy.getCookie()` yields `null`."
          }
        ]
      },
      {
        "type": "heading",
        "depth": 2,
        "children": [
          {
            "type": "text",
            "value": "Examples"
          }
        ]
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Session id"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "The "
          },
          {
            "type": "link",
            "title": null,
            "url": "/llm/markdown/app/references/recipes.md#Logging-In",
            "children": [
              {
                "type": "text",
                "value": "Logging In recipes"
              }
            ]
          },
          {
            "type": "text",
            "value": " use `cy.getCookie()` to test logging in with HTML web forms, XHR web forms, and single sign-on."
          }
        ]
      },
      {
        "type": "heading",
        "depth": 4,
        "children": [
          {
            "type": "text",
            "value": "Get `session_id` cookie after logging in"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "In this example, your server sends back a session cookie on login."
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "// assume the user just logged in\ncy.contains('Login').click()\ncy.url().should('include', 'profile')\n// retries until cookie with value=189jd09su\n// is found or default command timeout ends\ncy.getCookie('session_id').should('have.property', 'value', '189jd09su')"
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "To check that the cookie exists without comparing any of its properties, assert `exist`:"
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "cy.getCookie('my-session-cookie').should('exist')"
      },
      {
        "type": "heading",
        "depth": 4,
        "children": [
          {
            "type": "text",
            "value": "Send the session cookie's value in a request header"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "To pass the cookie's value to a later command, chain "
          },
          {
            "type": "link",
            "title": null,
            "url": "/llm/markdown/api/commands/its.md",
            "children": [
              {
                "type": "text",
                "value": "`.its('value')`"
              }
            ]
          },
          {
            "type": "text",
            "value": " and use the value inside "
          },
          {
            "type": "link",
            "title": null,
            "url": "/llm/markdown/api/commands/then.md",
            "children": [
              {
                "type": "text",
                "value": "`.then()`"
              }
            ]
          },
          {
            "type": "text",
            "value": ". Cypress runs the callback after `.its()` finds the value, so `cy.request()` gets the current value rather than one read when the test queued its commands."
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "cy.getCookie('session_id')\n  .its('value')\n  .then((token) => {\n    cy.request({\n      url: '/api/admin',\n      headers: {\n        'my-token-x': token,\n      },\n    })\n  })"
      },
      {
        "type": "heading",
        "depth": 4,
        "children": [
          {
            "type": "text",
            "value": "Check that the session cookie is removed after logout"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Assert `not.exist` to confirm a cookie is gone. The query retries until the assertion passes, so it waits for a logout request that clears the cookie after a short delay."
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "cy.contains('Log out').click()\ncy.getCookie('session_id').should('not.exist')"
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Assert on cookie properties from `cy.getCookie()`"
          }
        ]
      },
      {
        "type": "heading",
        "depth": 4,
        "children": [
          {
            "type": "text",
            "value": "Assert on one cookie property with `.its()`"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "link",
            "title": null,
            "url": "/llm/markdown/api/commands/its.md",
            "children": [
              {
                "type": "text",
                "value": "`.its()`"
              }
            ]
          },
          {
            "type": "text",
            "value": " yields a single property of the cookie. Because `.its()` is also a query, the assertion still retries `cy.getCookie()`, so the test waits for a cookie that hasn't been set yet."
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "cy.getCookie('csrf_token').its('value').should('have.length', 32)"
      },
      {
        "type": "heading",
        "depth": 4,
        "children": [
          {
            "type": "text",
            "value": "Check the security attributes of an auth cookie"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Assert `include` with the attributes your server must set. The assertion passes when the cookie has every listed property with the listed value."
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "cy.getCookie('session_id').should('include', {\n  httpOnly: true,\n  secure: true,\n  sameSite: 'strict',\n})"
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "`sameSite` is `'lax'`, `'strict'`, or `'no_restriction'` (the value for `SameSite=None`), or `'unspecified'` in Firefox when the cookie doesn't set one."
          }
        ]
      },
      {
        "type": "heading",
        "depth": 4,
        "children": [
          {
            "type": "text",
            "value": "Check that a remember-me cookie expires in the future"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "`expiry` is the time the cookie expires, in seconds since the Unix epoch. This example checks that a cookie lasts at least 29 more days:"
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "const twentyNineDays = 29 * 24 * 60 * 60\n\ncy.getCookie('remember_me')\n  .its('expiry')\n  .should('be.greaterThan', Date.now() / 1000 + twentyNineDays)"
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "A cookie set without an expiry date has no `expiry` property, so `.its('expiry')` fails for it."
          }
        ]
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Read a cookie on another domain with `cy.getCookie()`"
          }
        ]
      },
      {
        "type": "heading",
        "depth": 4,
        "children": [
          {
            "type": "text",
            "value": "Get a cookie set on a sibling API domain with `domain`"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "By default, `cy.getCookie()` reads cookies for the hostname of the application under test. Pass `domain` to read a cookie set for a different domain, such as an API on a sibling domain: `api.example.com` when your app runs on `app.example.com`."
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "cy.getCookie('refresh_token', { domain: 'api.example.com' }).should('exist')"
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Validate a `cy.session()` login with `cy.getCookie()`"
          }
        ]
      },
      {
        "type": "heading",
        "depth": 4,
        "children": [
          {
            "type": "text",
            "value": "Check the login cookie in a `cy.session()` validate function"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Use `cy.getCookie()` in the `validate` function of "
          },
          {
            "type": "link",
            "title": null,
            "url": "/llm/markdown/api/commands/session.md",
            "children": [
              {
                "type": "text",
                "value": "`cy.session()`"
              }
            ]
          },
          {
            "type": "text",
            "value": " to confirm the login cookie is set. Cypress saves the session's cookies again after `validate` passes, so a cookie that arrives after the login click is still part of the cached session."
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "cy.session(\n  username,\n  () => {\n    cy.visit('/login')\n    cy.get('#username').type(username)\n    cy.get('#password').type(password)\n    cy.contains('Log in').click()\n  },\n  {\n    validate() {\n      cy.getCookie('session_id').should('exist')\n    },\n  }\n)"
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "To confirm that your server still accepts a restored session, see "
          },
          {
            "type": "link",
            "title": null,
            "url": "/llm/markdown/api/commands/session.md#Validating-a-restored-session-with-validate",
            "children": [
              {
                "type": "text",
                "value": "validating the session"
              }
            ]
          },
          {
            "type": "text",
            "value": "."
          }
        ]
      },
      {
        "type": "heading",
        "depth": 2,
        "children": [
          {
            "type": "text",
            "value": "Notes"
          }
        ]
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Default cookie domain before visiting a page"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "The `domain` option defaults to the hostname of the application under test. Before "
          },
          {
            "type": "link",
            "title": null,
            "url": "/llm/markdown/api/commands/visit.md",
            "children": [
              {
                "type": "text",
                "value": "`cy.visit()`"
              }
            ]
          },
          {
            "type": "text",
            "value": " loads a page, the application under test is on `about:blank`, so Cypress uses the hostname it serves the spec from instead (usually `localhost`). Pass `domain` explicitly to work with cookies on another domain before visiting."
          }
        ]
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Which cookies `cy.getCookie()` matches by domain"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "`cy.getCookie()` looks for the cookie on the requested domain: the `domain` option if you pass one, otherwise the hostname of the application under test. It matches the same domain and any parent domain the cookie was set on, but not a subdomain or a sibling domain. When the application under test is on `app.example.com`, or you pass `domain: 'app.example.com'`:"
          }
        ]
      },
      {
        "type": "table",
        "align": [
          null,
          null
        ],
        "children": [
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Cookie set on"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Yielded by `cy.getCookie()`"
                  }
                ]
              }
            ]
          },
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "`app.example.com` (same domain)"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Yes"
                  }
                ]
              }
            ]
          },
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "`example.com` (parent domain)"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Yes"
                  }
                ]
              }
            ]
          },
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "`api.app.example.com` (subdomain)"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "No"
                  }
                ]
              }
            ]
          },
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "`api.example.com` (sibling domain)"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "No"
                  }
                ]
              }
            ]
          }
        ]
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Reading HttpOnly cookies with `cy.getCookie()`"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "`cy.getCookie()` reads cookies through the browser, so it yields cookies marked `HttpOnly`, such as most session cookies. Your application's JavaScript can't see those through `document.cookie`, so reading `document.cookie` in a test misses them."
          }
        ]
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Why `cy.getCookie()` yields `null`"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "If no cookie with the name is ever found, `cy.getCookie('session_id').should('exist')` fails with `Timed out retrying after 4000ms: expected null to exist`. Check these causes:"
          }
        ]
      },
      {
        "type": "list",
        "ordered": false,
        "start": null,
        "spread": false,
        "children": [
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "The name or domain doesn't match. See "
                  },
                  {
                    "type": "link",
                    "title": null,
                    "url": "#Which-cookies-cygetCookie-matches-by-domain",
                    "children": [
                      {
                        "type": "text",
                        "value": "which cookies `cy.getCookie()` matches"
                      }
                    ]
                  },
                  {
                    "type": "text",
                    "value": "."
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "The cookie was set in an earlier test. With "
                  },
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/app/core-concepts/test-isolation.md",
                    "children": [
                      {
                        "type": "text",
                        "value": "test isolation"
                      }
                    ]
                  },
                  {
                    "type": "text",
                    "value": " on, Cypress clears cookies before each test. Use "
                  },
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/api/commands/session.md",
                    "children": [
                      {
                        "type": "text",
                        "value": "`cy.session()`"
                      }
                    ]
                  },
                  {
                    "type": "text",
                    "value": " to keep a login across tests."
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "The cookie arrives after a slow request. Pass a longer `timeout` (see "
                  },
                  {
                    "type": "link",
                    "title": null,
                    "url": "#Timeouts",
                    "children": [
                      {
                        "type": "text",
                        "value": "Timeouts"
                      }
                    ]
                  },
                  {
                    "type": "text",
                    "value": ")."
                  }
                ]
              }
            ]
          }
        ]
      },
      {
        "type": "heading",
        "depth": 2,
        "children": [
          {
            "type": "text",
            "value": "Rules"
          }
        ]
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Requirements"
          }
        ]
      },
      {
        "type": "list",
        "ordered": false,
        "start": null,
        "spread": false,
        "children": [
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "`cy.getCookie()` requires being chained off of `cy`."
                  }
                ]
              }
            ]
          }
        ]
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Assertions"
          }
        ]
      },
      {
        "type": "list",
        "ordered": false,
        "start": null,
        "spread": false,
        "children": [
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "`cy.getCookie()` automatically "
                  },
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/app/core-concepts/retry-ability.md",
                    "children": [
                      {
                        "type": "text",
                        "value": "retries"
                      }
                    ]
                  },
                  {
                    "type": "text",
                    "value": " until all chained assertions have passed."
                  }
                ]
              }
            ]
          }
        ]
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Timeouts"
          }
        ]
      },
      {
        "type": "list",
        "ordered": false,
        "start": null,
        "spread": false,
        "children": [
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "`cy.getCookie()` can time out waiting for assertions you've added to pass, or for the browser to return the cookie. Both waits use the "
                  },
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/app/references/configuration.md#Timeouts",
                    "children": [
                      {
                        "type": "text",
                        "value": "`defaultCommandTimeout`"
                      }
                    ]
                  },
                  {
                    "type": "text",
                    "value": ", `4000` ms by default, or the `timeout` option, when passed."
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "If the application under test is on a different origin, `cy.getCookie()` retries until the command times out and then fails with a cross-origin error, even when you pass the `domain` option. Run it inside "
                  },
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/api/commands/origin.md",
                    "children": [
                      {
                        "type": "text",
                        "value": "`cy.origin()`"
                      }
                    ]
                  },
                  {
                    "type": "text",
                    "value": " to read cookies on that origin, or use "
                  },
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/api/commands/getallcookies.md",
                    "children": [
                      {
                        "type": "text",
                        "value": "`cy.getAllCookies()`"
                      }
                    ]
                  },
                  {
                    "type": "text",
                    "value": ", which reads cookies on every domain without that check."
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "If the browser returns an error before the first read succeeds, `cy.getCookie()` fails right away instead of retrying."
                  }
                ]
              }
            ]
          }
        ]
      },
      {
        "type": "heading",
        "depth": 2,
        "children": [
          {
            "type": "text",
            "value": "Command Log"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Get a browser cookie and make assertions about the object"
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "cy.getCookie('fakeCookie1').should('have.property', 'value', '123ABC')"
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "The commands above display in the Command Log as:"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "When you click `getCookie` in the Command Log, the console outputs the following. When no cookie matches, the console shows `null` as the yielded value, with a note that no cookie with that name was found."
          }
        ]
      },
      {
        "type": "heading",
        "depth": 2,
        "children": [
          {
            "type": "text",
            "value": "History"
          }
        ]
      },
      {
        "type": "table",
        "align": [
          null,
          null
        ],
        "children": [
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Version"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Changes"
                  }
                ]
              }
            ]
          },
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/app/references/changelog.md#16-0-0",
                    "children": [
                      {
                        "type": "text",
                        "value": "16.0.0"
                      }
                    ]
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Now a query that retries assertions, with `defaultCommandTimeout` as its timeout. See the "
                  },
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/app/references/migration-guide.md#cygetCookie-cygetCookies-and-cygetAllCookies-are-now-queries",
                    "children": [
                      {
                        "type": "text",
                        "value": "Migration Guide"
                      }
                    ]
                  },
                  {
                    "type": "text",
                    "value": "."
                  }
                ]
              }
            ]
          },
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/app/references/changelog.md#15-6-0",
                    "children": [
                      {
                        "type": "text",
                        "value": "15.6.0"
                      }
                    ]
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "In WebKit, prefers a cookie that matches the exact `domain`, falling back to a parent domain."
                  }
                ]
              }
            ]
          },
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/app/references/changelog.md#12-0-0",
                    "children": [
                      {
                        "type": "text",
                        "value": "12.0.0"
                      }
                    ]
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "The `domain` option defaults to the hostname instead of the superdomain."
                  }
                ]
              }
            ]
          },
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/app/references/changelog.md#11-0-0",
                    "children": [
                      {
                        "type": "text",
                        "value": "11.0.0"
                      }
                    ]
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Added `domain` option."
                  }
                ]
              }
            ]
          },
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/app/references/changelog.md#5-0-0",
                    "children": [
                      {
                        "type": "text",
                        "value": "5.0.0"
                      }
                    ]
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Removed `experimentalGetCookiesSameSite` and made `sameSite` property always available."
                  }
                ]
              }
            ]
          },
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/app/references/changelog.md#4-3-0",
                    "children": [
                      {
                        "type": "text",
                        "value": "4.3.0"
                      }
                    ]
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Added `sameSite` property when the `experimentalGetCookiesSameSite` configuration value is `true`."
                  }
                ]
              }
            ]
          }
        ]
      },
      {
        "type": "heading",
        "depth": 2,
        "children": [
          {
            "type": "text",
            "value": "See also"
          }
        ]
      },
      {
        "type": "list",
        "ordered": false,
        "start": null,
        "spread": false,
        "children": [
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/api/commands/clearcookie.md",
                    "children": [
                      {
                        "type": "text",
                        "value": "`cy.clearCookie()`"
                      }
                    ]
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/api/commands/getallcookies.md",
                    "children": [
                      {
                        "type": "text",
                        "value": "`cy.getAllCookies()`"
                      }
                    ]
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/api/commands/getcookies.md",
                    "children": [
                      {
                        "type": "text",
                        "value": "`cy.getCookies()`"
                      }
                    ]
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/api/commands/setcookie.md",
                    "children": [
                      {
                        "type": "text",
                        "value": "`cy.setCookie()`"
                      }
                    ]
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/api/cypress-api/cookies.md",
                    "children": [
                      {
                        "type": "text",
                        "value": "`Cypress.Cookies.debug()`"
                      }
                    ]
                  }
                ]
              }
            ]
          }
        ]
      }
    ]
  },
  "token_estimate": 1925
}