{
  "doc": {
    "id": "api/commands/location",
    "title": "cy.location()",
    "description": "Get the URL of the page that is currently active in Cypress as a location object, or one part of it, such as the pathname.",
    "section": "api",
    "source_path": "/llm/markdown/api/commands/location.md",
    "version": "f97f06d85653c51afe39a9bd3cefda946807f150",
    "updated_at": "2026-10-05T21:01:45.863Z",
    "headings": [
      {
        "id": "api/commands/location#location",
        "text": "location",
        "level": 1
      },
      {
        "id": "api/commands/location#syntax",
        "text": "Syntax",
        "level": 2
      },
      {
        "id": "api/commands/location#usage",
        "text": "Usage",
        "level": 3
      },
      {
        "id": "api/commands/location#arguments",
        "text": "Arguments",
        "level": 3
      },
      {
        "id": "api/commands/location#yields",
        "text": "Yields",
        "level": 3
      },
      {
        "id": "api/commands/location#when-not-given-a-key-argument",
        "text": "When not given a key argument",
        "level": 4
      },
      {
        "id": "api/commands/location#when-given-a-key-argument",
        "text": "When given a key argument",
        "level": 4
      },
      {
        "id": "api/commands/location#examples",
        "text": "Examples",
        "level": 2
      },
      {
        "id": "api/commands/location#key-argument",
        "text": "Key argument",
        "level": 3
      },
      {
        "id": "api/commands/location#assert-that-a-redirect-works",
        "text": "Assert that a redirect works",
        "level": 4
      },
      {
        "id": "api/commands/location#wait-longer-for-a-slow-redirect",
        "text": "Wait longer for a slow redirect",
        "level": 4
      },
      {
        "id": "api/commands/location#match-a-pathname-that-contains-a-generated-id",
        "text": "Match a pathname that contains a generated ID",
        "level": 4
      },
      {
        "id": "api/commands/location#save-part-of-the-url-for-later-in-the-test",
        "text": "Save part of the URL for later in the test",
        "level": 4
      },
      {
        "id": "api/commands/location#no-arguments",
        "text": "No arguments",
        "level": 3
      },
      {
        "id": "api/commands/location#make-assertions-about-every-location-property",
        "text": "Make assertions about every location property",
        "level": 4
      },
      {
        "id": "api/commands/location#check-location-for-query-params-and-pathname",
        "text": "Check location for query params and pathname",
        "level": 4
      },
      {
        "id": "api/commands/location#query-parameters",
        "text": "Query parameters",
        "level": 3
      },
      {
        "id": "api/commands/location#read-a-query-parameter",
        "text": "Read a query parameter",
        "level": 4
      },
      {
        "id": "api/commands/location#assert-on-query-parameters-in-any-order",
        "text": "Assert on query parameters in any order",
        "level": 4
      },
      {
        "id": "api/commands/location#cross-origin-redirects",
        "text": "Cross-origin redirects",
        "level": 3
      },
      {
        "id": "api/commands/location#assert-that-sign-in-redirects-to-an-identity-provider",
        "text": "Assert that sign-in redirects to an identity provider",
        "level": 4
      },
      {
        "id": "api/commands/location#notes",
        "text": "Notes",
        "level": 2
      },
      {
        "id": "api/commands/location#cy-location-yields-a-plain-object-not-window-location",
        "text": "cy.location() yields a plain object, not window.location",
        "level": 3
      },
      {
        "id": "api/commands/location#cross-origin-pages-and-cy-location",
        "text": "Cross-origin pages and cy.location()",
        "level": 3
      },
      {
        "id": "api/commands/location#choosing-between-cy-location-cy-url-and-cy-hash",
        "text": "Choosing between cy.location(), cy.url(), and cy.hash()",
        "level": 3
      },
      {
        "id": "api/commands/location#pass-a-key-instead-of-chaining-its",
        "text": "Pass a key instead of chaining .its()",
        "level": 3
      },
      {
        "id": "api/commands/location#rules",
        "text": "Rules",
        "level": 2
      },
      {
        "id": "api/commands/location#requirements",
        "text": "Requirements",
        "level": 3
      },
      {
        "id": "api/commands/location#assertions",
        "text": "Assertions",
        "level": 3
      },
      {
        "id": "api/commands/location#timeouts",
        "text": "Timeouts",
        "level": 3
      },
      {
        "id": "api/commands/location#command-log",
        "text": "Command Log",
        "level": 2
      },
      {
        "id": "api/commands/location#history",
        "text": "History",
        "level": 2
      },
      {
        "id": "api/commands/location#see-also",
        "text": "See also",
        "level": 2
      }
    ]
  },
  "chunks": [
    {
      "id": "api/commands/location#syntax",
      "doc_id": "api/commands/location",
      "heading": "Syntax",
      "heading_level": 2,
      "content_markdown": "## Syntax\n\n```\ncy.location()\ncy.location(key)\ncy.location(options)\ncy.location(key, options)\n```\n\n### Usage\n\n**Correct Usage**\n\n```\ncy.location() // Get location object\ncy.location('host') // Get the host of the location object\ncy.location('port') // Get the port of the location object\n```\n\n**Incorrect Usage**\n\n```\ncy.get('a').location() // Ignores the link, yields the page's location\ncy.location('assign') // Errors, the location object has no assign key\n```\n\n`cy.location()` reads the page's URL, not an element's `href`. To check where a link points, assert on the link's own properties instead:\n\n```\ncy.get('a').should('have.prop', 'pathname', '/users')\n```\n\n### Arguments\n\n**key _(String)_**\n\nOne of the properties listed under [Yields](#Yields), such as `'pathname'`. `cy.location()` yields that property's value instead of the full location object, and fails when the location object has no property named `key`.\n\n**options _(Object)_**\n\nPass in an options object to change the default behavior of `cy.location()`.\n\n| Option | Default | Description |\n| --- | --- | --- |\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.location()` to resolve before [timing out](#Timeouts) |\n\n### Yields\n\n`cy.location()` is a query, and it is _safe_ to chain further commands.\n\n#### When not given a `key` argument\n\n`cy.location()` yields a plain object with these properties. The example values are for the URL `https://example.com:8080/app/users?tab=1#section`.\n\n| Property | Type | Example value |\n| --- | --- | --- |\n| `hash` | string | `'#section'` |\n| `host` | string | `'example.com:8080'` |\n| `hostname` | string | `'example.com'` |\n| `href` | string | `'https://example.com:8080/app/users?tab=1#section'` |\n| `origin` | string | `'https://example.com:8080'` |\n| `pathname` | string | `'/app/users'` |\n| `port` | string | `'8080'` |\n| `protocol` | string | `'https:'` |\n| `search` | string | `'?tab=1'` |\n| `searchParams` | [`URLSearchParams`](https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams) | `searchParams.get('tab')` returns `'1'` |\n\n#### When given a `key` argument\n\n*   `cy.location()` yields the value of that property: a string, or a `URLSearchParams` object for `searchParams`\n*   `cy.location()` fails when the location object has no property named `key`\n\nThese diagrams show where each key sits in a URL:\n\nIn a hash-based route, a query string after the `#` is part of the hash:\n",
      "section": "api",
      "anchors": [
        "syntax"
      ],
      "path": "/llm/json/chunked/api/commands/location.json",
      "token_estimate": 485
    },
    {
      "id": "api/commands/location#usage",
      "doc_id": "api/commands/location",
      "heading": "Usage",
      "heading_level": 3,
      "content_markdown": "### Usage\n\n**Correct Usage**\n\n```\ncy.location() // Get location object\ncy.location('host') // Get the host of the location object\ncy.location('port') // Get the port of the location object\n```\n\n**Incorrect Usage**\n\n```\ncy.get('a').location() // Ignores the link, yields the page's location\ncy.location('assign') // Errors, the location object has no assign key\n```\n\n`cy.location()` reads the page's URL, not an element's `href`. To check where a link points, assert on the link's own properties instead:\n\n```\ncy.get('a').should('have.prop', 'pathname', '/users')\n```\n",
      "section": "api",
      "anchors": [
        "usage"
      ],
      "path": "/llm/json/chunked/api/commands/location.json",
      "token_estimate": 105
    },
    {
      "id": "api/commands/location#arguments",
      "doc_id": "api/commands/location",
      "heading": "Arguments",
      "heading_level": 3,
      "content_markdown": "### Arguments\n\n**key _(String)_**\n\nOne of the properties listed under [Yields](#Yields), such as `'pathname'`. `cy.location()` yields that property's value instead of the full location object, and fails when the location object has no property named `key`.\n\n**options _(Object)_**\n\nPass in an options object to change the default behavior of `cy.location()`.\n\n| Option | Default | Description |\n| --- | --- | --- |\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.location()` to resolve before [timing out](#Timeouts) |\n",
      "section": "api",
      "anchors": [
        "arguments"
      ],
      "path": "/llm/json/chunked/api/commands/location.json",
      "token_estimate": 124
    },
    {
      "id": "api/commands/location#yields",
      "doc_id": "api/commands/location",
      "heading": "Yields",
      "heading_level": 3,
      "content_markdown": "### Yields\n\n`cy.location()` is a query, and it is _safe_ to chain further commands.\n\n#### When not given a `key` argument\n\n`cy.location()` yields a plain object with these properties. The example values are for the URL `https://example.com:8080/app/users?tab=1#section`.\n\n| Property | Type | Example value |\n| --- | --- | --- |\n| `hash` | string | `'#section'` |\n| `host` | string | `'example.com:8080'` |\n| `hostname` | string | `'example.com'` |\n| `href` | string | `'https://example.com:8080/app/users?tab=1#section'` |\n| `origin` | string | `'https://example.com:8080'` |\n| `pathname` | string | `'/app/users'` |\n| `port` | string | `'8080'` |\n| `protocol` | string | `'https:'` |\n| `search` | string | `'?tab=1'` |\n| `searchParams` | [`URLSearchParams`](https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams) | `searchParams.get('tab')` returns `'1'` |\n\n#### When given a `key` argument\n\n*   `cy.location()` yields the value of that property: a string, or a `URLSearchParams` object for `searchParams`\n*   `cy.location()` fails when the location object has no property named `key`\n\nThese diagrams show where each key sits in a URL:\n\nIn a hash-based route, a query string after the `#` is part of the hash:\n",
      "section": "api",
      "anchors": [
        "yields"
      ],
      "path": "/llm/json/chunked/api/commands/location.json",
      "token_estimate": 244
    },
    {
      "id": "api/commands/location#when-not-given-a-key-argument",
      "doc_id": "api/commands/location",
      "heading": "When not given a key argument",
      "heading_level": 4,
      "content_markdown": "#### When not given a `key` argument\n\n`cy.location()` yields a plain object with these properties. The example values are for the URL `https://example.com:8080/app/users?tab=1#section`.\n\n| Property | Type | Example value |\n| --- | --- | --- |\n| `hash` | string | `'#section'` |\n| `host` | string | `'example.com:8080'` |\n| `hostname` | string | `'example.com'` |\n| `href` | string | `'https://example.com:8080/app/users?tab=1#section'` |\n| `origin` | string | `'https://example.com:8080'` |\n| `pathname` | string | `'/app/users'` |\n| `port` | string | `'8080'` |\n| `protocol` | string | `'https:'` |\n| `search` | string | `'?tab=1'` |\n| `searchParams` | [`URLSearchParams`](https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams) | `searchParams.get('tab')` returns `'1'` |\n",
      "section": "api",
      "anchors": [
        "when-not-given-a-key-argument"
      ],
      "path": "/llm/json/chunked/api/commands/location.json",
      "token_estimate": 147
    },
    {
      "id": "api/commands/location#when-given-a-key-argument",
      "doc_id": "api/commands/location",
      "heading": "When given a key argument",
      "heading_level": 4,
      "content_markdown": "#### When given a `key` argument\n\n*   `cy.location()` yields the value of that property: a string, or a `URLSearchParams` object for `searchParams`\n*   `cy.location()` fails when the location object has no property named `key`\n\nThese diagrams show where each key sits in a URL:\n\nIn a hash-based route, a query string after the `#` is part of the hash:\n",
      "section": "api",
      "anchors": [
        "when-given-a-key-argument"
      ],
      "path": "/llm/json/chunked/api/commands/location.json",
      "token_estimate": 79
    },
    {
      "id": "api/commands/location#examples",
      "doc_id": "api/commands/location",
      "heading": "Examples",
      "heading_level": 2,
      "content_markdown": "## Examples\n\n### Key argument\n\n#### Assert that a redirect works\n\nGrab only the `pathname` and add an assertion.\n\n```\ncy.visit('http://localhost:3000/admin')\ncy.location('pathname').should('eq', '/login')\n```\n\n#### Wait longer for a slow redirect\n\nPass a `timeout` when a redirect takes longer than [`defaultCommandTimeout`](/llm/markdown/app/references/configuration.md#Timeouts), such as after a login request. Cypress retries the assertion until the pathname matches or the timeout passes.\n\n```\ncy.get('[data-cy=\"login\"]').click()\ncy.location('pathname', { timeout: 10000 }).should('eq', '/dashboard')\n```\n\n#### Match a pathname that contains a generated ID\n\nWhen your application creates a record and navigates to it, the ID in the URL isn't known ahead of time. Match the pathname against a regular expression instead.\n\n```\ncy.get('[data-cy=\"create-user\"]').click()\ncy.location('pathname').should('match', /^\\/users\\/\\d+$/)\n```\n\n#### Save part of the URL for later in the test\n\nTransform the value in [`.then()`](/llm/markdown/api/commands/then.md) and save it with [`.as()`](/llm/markdown/api/commands/as.md) to use it in a later command.\n\n```\ncy.location('pathname')\n  .then((pathname) => pathname.split('/').pop())\n  .as('userId')\n\ncy.get('@userId').then((userId) => {\n  cy.request(`/api/users/${userId}`).its('status').should('eq', 200)\n})\n```\n\n### No arguments\n\n#### Make assertions about every location property\n\n```\ncy.visit('http://localhost:8000/app/index.html?q=dan#/users/123/edit')\n\ncy.location().should((loc) => {\n  expect(loc.hash).to.eq('#/users/123/edit')\n  expect(loc.host).to.eq('localhost:8000')\n  expect(loc.hostname).to.eq('localhost')\n  expect(loc.href).to.eq(\n    'http://localhost:8000/app/index.html?q=dan#/users/123/edit'\n  )\n  expect(loc.origin).to.eq('http://localhost:8000')\n  expect(loc.pathname).to.eq('/app/index.html')\n  expect(loc.port).to.eq('8000')\n  expect(loc.protocol).to.eq('http:')\n  expect(loc.search).to.eq('?q=dan')\n  expect(loc.searchParams.get('q')).to.eq('dan')\n})\n```\n\n#### Check location for query params and pathname\n\nPass a callback to [`.should()`](/llm/markdown/api/commands/should.md) to work with the location object directly. Cypress retries the callback until every assertion in it passes.\n\nindex.html\n\n```\n<form action=\"/users\">\n  <input id=\"search\" name=\"search\" />\n</form>\n```\n\nspec.cy.js\n\n```\ncy.visit('http://localhost:3000/')\ncy.get('#search').type('niklas{enter}')\ncy.location().should((loc) => {\n  expect(loc.search).to.eq('?search=niklas')\n  expect(loc.pathname).to.eq('/users')\n})\n```\n\n### Query parameters\n\n#### Read a query parameter\n\n`searchParams` yields a `URLSearchParams` object, so you can call its methods with [`.invoke()`](/llm/markdown/api/commands/invoke.md).\n\n```\ncy.visit('http://localhost:3000/users?page=2&sort=name')\ncy.location('searchParams').invoke('get', 'sort').should('eq', 'name')\n```\n\n#### Assert on query parameters in any order\n\nComparing `search` to a string fails when your application writes the same parameters in a different order. Asserting on `searchParams` checks each parameter by name, and `getAll()` reads a parameter that appears more than once.\n\n```\ncy.visit('http://localhost:3000/posts?sort=name&tag=cypress&page=2&tag=testing')\ncy.location('searchParams').should((params) => {\n  expect(params.get('page')).to.eq('2')\n  expect(params.get('sort')).to.eq('name')\n  expect(params.getAll('tag')).to.deep.eq(['cypress', 'testing'])\n})\n```\n\n### Cross-origin redirects\n\n#### Assert that sign-in redirects to an identity provider\n\n`cy.location()` reads the URL after your application navigates to another origin, so you can confirm where a sign-in flow landed before you interact with that page inside [`cy.origin()`](/llm/markdown/api/commands/origin.md).\n\n```\ncy.visit('http://localhost:3000/')\ncy.contains('a', 'Sign in').click()\n\ncy.location('origin').should('eq', 'http://auth.example.com')\ncy.location('searchParams')\n  .invoke('get', 'redirect_uri')\n  .should('eq', 'http://localhost:3000/callback')\n\ncy.origin('http://auth.example.com', () => {\n  cy.get('input[name=\"email\"]').type('user@example.com')\n})\n```\n",
      "section": "api",
      "anchors": [
        "examples"
      ],
      "path": "/llm/json/chunked/api/commands/location.json",
      "token_estimate": 495
    },
    {
      "id": "api/commands/location#key-argument",
      "doc_id": "api/commands/location",
      "heading": "Key argument",
      "heading_level": 3,
      "content_markdown": "### Key argument\n\n#### Assert that a redirect works\n\nGrab only the `pathname` and add an assertion.\n\n```\ncy.visit('http://localhost:3000/admin')\ncy.location('pathname').should('eq', '/login')\n```\n\n#### Wait longer for a slow redirect\n\nPass a `timeout` when a redirect takes longer than [`defaultCommandTimeout`](/llm/markdown/app/references/configuration.md#Timeouts), such as after a login request. Cypress retries the assertion until the pathname matches or the timeout passes.\n\n```\ncy.get('[data-cy=\"login\"]').click()\ncy.location('pathname', { timeout: 10000 }).should('eq', '/dashboard')\n```\n\n#### Match a pathname that contains a generated ID\n\nWhen your application creates a record and navigates to it, the ID in the URL isn't known ahead of time. Match the pathname against a regular expression instead.\n\n```\ncy.get('[data-cy=\"create-user\"]').click()\ncy.location('pathname').should('match', /^\\/users\\/\\d+$/)\n```\n\n#### Save part of the URL for later in the test\n\nTransform the value in [`.then()`](/llm/markdown/api/commands/then.md) and save it with [`.as()`](/llm/markdown/api/commands/as.md) to use it in a later command.\n\n```\ncy.location('pathname')\n  .then((pathname) => pathname.split('/').pop())\n  .as('userId')\n\ncy.get('@userId').then((userId) => {\n  cy.request(`/api/users/${userId}`).its('status').should('eq', 200)\n})\n```\n",
      "section": "api",
      "anchors": [
        "key-argument"
      ],
      "path": "/llm/json/chunked/api/commands/location.json",
      "token_estimate": 199
    },
    {
      "id": "api/commands/location#wait-longer-for-a-slow-redirect",
      "doc_id": "api/commands/location",
      "heading": "Wait longer for a slow redirect",
      "heading_level": 4,
      "content_markdown": "#### Wait longer for a slow redirect\n\nPass a `timeout` when a redirect takes longer than [`defaultCommandTimeout`](/llm/markdown/app/references/configuration.md#Timeouts), such as after a login request. Cypress retries the assertion until the pathname matches or the timeout passes.\n\n```\ncy.get('[data-cy=\"login\"]').click()\ncy.location('pathname', { timeout: 10000 }).should('eq', '/dashboard')\n```\n",
      "section": "api",
      "anchors": [
        "wait-longer-for-a-slow-redirect"
      ],
      "path": "/llm/json/chunked/api/commands/location.json",
      "token_estimate": 59
    },
    {
      "id": "api/commands/location#match-a-pathname-that-contains-a-generated-id",
      "doc_id": "api/commands/location",
      "heading": "Match a pathname that contains a generated ID",
      "heading_level": 4,
      "content_markdown": "#### Match a pathname that contains a generated ID\n\nWhen your application creates a record and navigates to it, the ID in the URL isn't known ahead of time. Match the pathname against a regular expression instead.\n\n```\ncy.get('[data-cy=\"create-user\"]').click()\ncy.location('pathname').should('match', /^\\/users\\/\\d+$/)\n```\n",
      "section": "api",
      "anchors": [
        "match-a-pathname-that-contains-a-generated-id"
      ],
      "path": "/llm/json/chunked/api/commands/location.json",
      "token_estimate": 56
    },
    {
      "id": "api/commands/location#save-part-of-the-url-for-later-in-the-test",
      "doc_id": "api/commands/location",
      "heading": "Save part of the URL for later in the test",
      "heading_level": 4,
      "content_markdown": "#### Save part of the URL for later in the test\n\nTransform the value in [`.then()`](/llm/markdown/api/commands/then.md) and save it with [`.as()`](/llm/markdown/api/commands/as.md) to use it in a later command.\n\n```\ncy.location('pathname')\n  .then((pathname) => pathname.split('/').pop())\n  .as('userId')\n\ncy.get('@userId').then((userId) => {\n  cy.request(`/api/users/${userId}`).its('status').should('eq', 200)\n})\n```\n",
      "section": "api",
      "anchors": [
        "save-part-of-the-url-for-later-in-the-test"
      ],
      "path": "/llm/json/chunked/api/commands/location.json",
      "token_estimate": 55
    },
    {
      "id": "api/commands/location#no-arguments",
      "doc_id": "api/commands/location",
      "heading": "No arguments",
      "heading_level": 3,
      "content_markdown": "### No arguments\n\n#### Make assertions about every location property\n\n```\ncy.visit('http://localhost:8000/app/index.html?q=dan#/users/123/edit')\n\ncy.location().should((loc) => {\n  expect(loc.hash).to.eq('#/users/123/edit')\n  expect(loc.host).to.eq('localhost:8000')\n  expect(loc.hostname).to.eq('localhost')\n  expect(loc.href).to.eq(\n    'http://localhost:8000/app/index.html?q=dan#/users/123/edit'\n  )\n  expect(loc.origin).to.eq('http://localhost:8000')\n  expect(loc.pathname).to.eq('/app/index.html')\n  expect(loc.port).to.eq('8000')\n  expect(loc.protocol).to.eq('http:')\n  expect(loc.search).to.eq('?q=dan')\n  expect(loc.searchParams.get('q')).to.eq('dan')\n})\n```\n\n#### Check location for query params and pathname\n\nPass a callback to [`.should()`](/llm/markdown/api/commands/should.md) to work with the location object directly. Cypress retries the callback until every assertion in it passes.\n\nindex.html\n\n```\n<form action=\"/users\">\n  <input id=\"search\" name=\"search\" />\n</form>\n```\n\nspec.cy.js\n\n```\ncy.visit('http://localhost:3000/')\ncy.get('#search').type('niklas{enter}')\ncy.location().should((loc) => {\n  expect(loc.search).to.eq('?search=niklas')\n  expect(loc.pathname).to.eq('/users')\n})\n```\n",
      "section": "api",
      "anchors": [
        "no-arguments"
      ],
      "path": "/llm/json/chunked/api/commands/location.json",
      "token_estimate": 107
    },
    {
      "id": "api/commands/location#check-location-for-query-params-and-pathname",
      "doc_id": "api/commands/location",
      "heading": "Check location for query params and pathname",
      "heading_level": 4,
      "content_markdown": "#### Check location for query params and pathname\n\nPass a callback to [`.should()`](/llm/markdown/api/commands/should.md) to work with the location object directly. Cypress retries the callback until every assertion in it passes.\n\nindex.html\n\n```\n<form action=\"/users\">\n  <input id=\"search\" name=\"search\" />\n</form>\n```\n\nspec.cy.js\n\n```\ncy.visit('http://localhost:3000/')\ncy.get('#search').type('niklas{enter}')\ncy.location().should((loc) => {\n  expect(loc.search).to.eq('?search=niklas')\n  expect(loc.pathname).to.eq('/users')\n})\n```\n",
      "section": "api",
      "anchors": [
        "check-location-for-query-params-and-pathname"
      ],
      "path": "/llm/json/chunked/api/commands/location.json",
      "token_estimate": 68
    },
    {
      "id": "api/commands/location#query-parameters",
      "doc_id": "api/commands/location",
      "heading": "Query parameters",
      "heading_level": 3,
      "content_markdown": "### Query parameters\n\n#### Read a query parameter\n\n`searchParams` yields a `URLSearchParams` object, so you can call its methods with [`.invoke()`](/llm/markdown/api/commands/invoke.md).\n\n```\ncy.visit('http://localhost:3000/users?page=2&sort=name')\ncy.location('searchParams').invoke('get', 'sort').should('eq', 'name')\n```\n\n#### Assert on query parameters in any order\n\nComparing `search` to a string fails when your application writes the same parameters in a different order. Asserting on `searchParams` checks each parameter by name, and `getAll()` reads a parameter that appears more than once.\n\n```\ncy.visit('http://localhost:3000/posts?sort=name&tag=cypress&page=2&tag=testing')\ncy.location('searchParams').should((params) => {\n  expect(params.get('page')).to.eq('2')\n  expect(params.get('sort')).to.eq('name')\n  expect(params.getAll('tag')).to.deep.eq(['cypress', 'testing'])\n})\n```\n",
      "section": "api",
      "anchors": [
        "query-parameters"
      ],
      "path": "/llm/json/chunked/api/commands/location.json",
      "token_estimate": 108
    },
    {
      "id": "api/commands/location#assert-on-query-parameters-in-any-order",
      "doc_id": "api/commands/location",
      "heading": "Assert on query parameters in any order",
      "heading_level": 4,
      "content_markdown": "#### Assert on query parameters in any order\n\nComparing `search` to a string fails when your application writes the same parameters in a different order. Asserting on `searchParams` checks each parameter by name, and `getAll()` reads a parameter that appears more than once.\n\n```\ncy.visit('http://localhost:3000/posts?sort=name&tag=cypress&page=2&tag=testing')\ncy.location('searchParams').should((params) => {\n  expect(params.get('page')).to.eq('2')\n  expect(params.get('sort')).to.eq('name')\n  expect(params.getAll('tag')).to.deep.eq(['cypress', 'testing'])\n})\n```\n",
      "section": "api",
      "anchors": [
        "assert-on-query-parameters-in-any-order"
      ],
      "path": "/llm/json/chunked/api/commands/location.json",
      "token_estimate": 72
    },
    {
      "id": "api/commands/location#cross-origin-redirects",
      "doc_id": "api/commands/location",
      "heading": "Cross-origin redirects",
      "heading_level": 3,
      "content_markdown": "### Cross-origin redirects\n\n#### Assert that sign-in redirects to an identity provider\n\n`cy.location()` reads the URL after your application navigates to another origin, so you can confirm where a sign-in flow landed before you interact with that page inside [`cy.origin()`](/llm/markdown/api/commands/origin.md).\n\n```\ncy.visit('http://localhost:3000/')\ncy.contains('a', 'Sign in').click()\n\ncy.location('origin').should('eq', 'http://auth.example.com')\ncy.location('searchParams')\n  .invoke('get', 'redirect_uri')\n  .should('eq', 'http://localhost:3000/callback')\n\ncy.origin('http://auth.example.com', () => {\n  cy.get('input[name=\"email\"]').type('user@example.com')\n})\n```\n",
      "section": "api",
      "anchors": [
        "cross-origin-redirects"
      ],
      "path": "/llm/json/chunked/api/commands/location.json",
      "token_estimate": 79
    },
    {
      "id": "api/commands/location#assert-that-sign-in-redirects-to-an-identity-provider",
      "doc_id": "api/commands/location",
      "heading": "Assert that sign-in redirects to an identity provider",
      "heading_level": 4,
      "content_markdown": "#### Assert that sign-in redirects to an identity provider\n\n`cy.location()` reads the URL after your application navigates to another origin, so you can confirm where a sign-in flow landed before you interact with that page inside [`cy.origin()`](/llm/markdown/api/commands/origin.md).\n\n```\ncy.visit('http://localhost:3000/')\ncy.contains('a', 'Sign in').click()\n\ncy.location('origin').should('eq', 'http://auth.example.com')\ncy.location('searchParams')\n  .invoke('get', 'redirect_uri')\n  .should('eq', 'http://localhost:3000/callback')\n\ncy.origin('http://auth.example.com', () => {\n  cy.get('input[name=\"email\"]').type('user@example.com')\n})\n```\n",
      "section": "api",
      "anchors": [
        "assert-that-sign-in-redirects-to-an-identity-provider"
      ],
      "path": "/llm/json/chunked/api/commands/location.json",
      "token_estimate": 75
    },
    {
      "id": "api/commands/location#notes",
      "doc_id": "api/commands/location",
      "heading": "Notes",
      "heading_level": 2,
      "content_markdown": "## Notes\n\n### `cy.location()` yields a plain object, not `window.location`\n\n`cy.location()` reads the current URL of the application under test from the browser and yields a plain object with the properties listed under [Yields](#Yields). It has none of the `window.location` methods, such as `assign()` or `reload()`. Read `href` when you need the full URL as a string.\n\nChanging a property on the real `window.location` object navigates the browser away. Changing a property on the object `cy.location()` yields has no effect on navigation.\n\nLogging the yielded object shows only its URL properties:\n\n```\ncy.location().then((loc) => {\n  console.log(loc)\n})\n```\n\n### Cross-origin pages and `cy.location()`\n\nCypress reads the URL through the browser's automation protocol instead of the application's `window`, so `cy.location()` works after your application navigates to another origin, without wrapping it in [`cy.origin()`](/llm/markdown/api/commands/origin.md). See [Assert that sign-in redirects to an identity provider](#Assert-that-sign-in-redirects-to-an-identity-provider).\n\n### Choosing between `cy.location()`, `cy.url()`, and `cy.hash()`\n\nAll three commands read the same URL from the browser. Use the one that yields what you're asserting on:\n\n*   [`cy.url()`](/llm/markdown/api/commands/url.md) yields the full URL as a string, the same value as `cy.location('href')`\n*   [`cy.hash()`](/llm/markdown/api/commands/hash.md) yields the fragment, the same value as `cy.location('hash')`\n*   `cy.location()` yields any other part of the URL, such as `pathname`, `host`, or `searchParams`, or the whole location object\n\nIn a hash-based route, a query string after the `#` belongs to the hash, so `search` and `searchParams` don't include it. See [Query strings inside a hash route](/llm/markdown/api/commands/hash.md#Query-strings-inside-a-hash-route).\n\n### Pass a key instead of chaining `.its()`\n\n`cy.location('pathname')` and `cy.location().its('pathname')` both retry until the assertion that follows passes. Passing the key reads more clearly and shows the key next to `location` in the Command Log.\n\n```\ncy.location('pathname').should('eq', '/users')\n```\n",
      "section": "api",
      "anchors": [
        "notes"
      ],
      "path": "/llm/json/chunked/api/commands/location.json",
      "token_estimate": 372
    },
    {
      "id": "api/commands/location#cy-location-yields-a-plain-object-not-window-location",
      "doc_id": "api/commands/location",
      "heading": "cy.location() yields a plain object, not window.location",
      "heading_level": 3,
      "content_markdown": "### `cy.location()` yields a plain object, not `window.location`\n\n`cy.location()` reads the current URL of the application under test from the browser and yields a plain object with the properties listed under [Yields](#Yields). It has none of the `window.location` methods, such as `assign()` or `reload()`. Read `href` when you need the full URL as a string.\n\nChanging a property on the real `window.location` object navigates the browser away. Changing a property on the object `cy.location()` yields has no effect on navigation.\n\nLogging the yielded object shows only its URL properties:\n\n```\ncy.location().then((loc) => {\n  console.log(loc)\n})\n```\n",
      "section": "api",
      "anchors": [
        "cy-location-yields-a-plain-object-not-window-location"
      ],
      "path": "/llm/json/chunked/api/commands/location.json",
      "token_estimate": 128
    },
    {
      "id": "api/commands/location#cross-origin-pages-and-cy-location",
      "doc_id": "api/commands/location",
      "heading": "Cross-origin pages and cy.location()",
      "heading_level": 3,
      "content_markdown": "### Cross-origin pages and `cy.location()`\n\nCypress reads the URL through the browser's automation protocol instead of the application's `window`, so `cy.location()` works after your application navigates to another origin, without wrapping it in [`cy.origin()`](/llm/markdown/api/commands/origin.md). See [Assert that sign-in redirects to an identity provider](#Assert-that-sign-in-redirects-to-an-identity-provider).\n",
      "section": "api",
      "anchors": [
        "cross-origin-pages-and-cy-location"
      ],
      "path": "/llm/json/chunked/api/commands/location.json",
      "token_estimate": 57
    },
    {
      "id": "api/commands/location#choosing-between-cy-location-cy-url-and-cy-hash",
      "doc_id": "api/commands/location",
      "heading": "Choosing between cy.location(), cy.url(), and cy.hash()",
      "heading_level": 3,
      "content_markdown": "### Choosing between `cy.location()`, `cy.url()`, and `cy.hash()`\n\nAll three commands read the same URL from the browser. Use the one that yields what you're asserting on:\n\n*   [`cy.url()`](/llm/markdown/api/commands/url.md) yields the full URL as a string, the same value as `cy.location('href')`\n*   [`cy.hash()`](/llm/markdown/api/commands/hash.md) yields the fragment, the same value as `cy.location('hash')`\n*   `cy.location()` yields any other part of the URL, such as `pathname`, `host`, or `searchParams`, or the whole location object\n\nIn a hash-based route, a query string after the `#` belongs to the hash, so `search` and `searchParams` don't include it. See [Query strings inside a hash route](/llm/markdown/api/commands/hash.md#Query-strings-inside-a-hash-route).\n",
      "section": "api",
      "anchors": [
        "choosing-between-cy-location-cy-url-and-cy-hash"
      ],
      "path": "/llm/json/chunked/api/commands/location.json",
      "token_estimate": 131
    },
    {
      "id": "api/commands/location#pass-a-key-instead-of-chaining-its",
      "doc_id": "api/commands/location",
      "heading": "Pass a key instead of chaining .its()",
      "heading_level": 3,
      "content_markdown": "### Pass a key instead of chaining `.its()`\n\n`cy.location('pathname')` and `cy.location().its('pathname')` both retry until the assertion that follows passes. Passing the key reads more clearly and shows the key next to `location` in the Command Log.\n\n```\ncy.location('pathname').should('eq', '/users')\n```\n",
      "section": "api",
      "anchors": [
        "pass-a-key-instead-of-chaining-its"
      ],
      "path": "/llm/json/chunked/api/commands/location.json",
      "token_estimate": 53
    },
    {
      "id": "api/commands/location#rules",
      "doc_id": "api/commands/location",
      "heading": "Rules",
      "heading_level": 2,
      "content_markdown": "## Rules\n\n### Requirements\n\n*   `cy.location()` requires being chained off of `cy`.\n\n### Assertions\n\n*   `cy.location()` automatically [retries](/llm/markdown/app/core-concepts/retry-ability.md) until all chained assertions have passed\n\n### Timeouts\n\n*   `cy.location()` can time out waiting for the browser to report the page's URL.\n*   `cy.location()` can time out waiting for assertions you've added to pass.\n",
      "section": "api",
      "anchors": [
        "rules"
      ],
      "path": "/llm/json/chunked/api/commands/location.json",
      "token_estimate": 69
    },
    {
      "id": "api/commands/location#command-log",
      "doc_id": "api/commands/location",
      "heading": "Command Log",
      "heading_level": 2,
      "content_markdown": "## Command Log\n\n**_Assert on the location's href_**\n\n```\ncy.location().should((loc) => {\n  expect(loc.href).to.include('commands/querying')\n})\n```\n\nThe commands above display in the Command Log as:\n\nWhen clicking on `location` within the Command Log, the console outputs the following:\n",
      "section": "api",
      "anchors": [
        "command-log"
      ],
      "path": "/llm/json/chunked/api/commands/location.json",
      "token_estimate": 49
    },
    {
      "id": "api/commands/location#history",
      "doc_id": "api/commands/location",
      "heading": "History",
      "heading_level": 2,
      "content_markdown": "## History\n\n| Version | Changes |\n| --- | --- |\n| [15.18.1](/llm/markdown/app/references/changelog.md#15-18-1) | Experimental WebKit yields the same location object as other browsers |\n| [15.0.0](/llm/markdown/app/references/changelog.md#15-0-0) | In Chromium-based browsers and Firefox, reads the URL through the browser's automation protocol. The yielded object includes `searchParams` and no longer includes `toString` |\n",
      "section": "api",
      "anchors": [
        "history"
      ],
      "path": "/llm/json/chunked/api/commands/location.json",
      "token_estimate": 71
    }
  ]
}