{
  "doc": {
    "id": "api/commands/intercept",
    "title": "intercept | Cypress Documentation",
    "description": "Spy and stub network requests and responses.",
    "section": "api",
    "source_path": "/llm/markdown/api/commands/intercept.md",
    "version": "48b03b5502f7aea1d0454750cce208f775403542",
    "updated_at": "2026-05-20T19:00:20.270Z",
    "headings": [
      {
        "id": "api/commands/intercept#intercept",
        "text": "intercept",
        "level": 1
      },
      {
        "id": "api/commands/intercept#syntax",
        "text": "Syntax",
        "level": 2
      },
      {
        "id": "api/commands/intercept#usage",
        "text": "Usage",
        "level": 3
      },
      {
        "id": "api/commands/intercept#arguments",
        "text": "Arguments",
        "level": 3
      },
      {
        "id": "api/commands/intercept#method-string",
        "text": "method (String)",
        "level": 4
      },
      {
        "id": "api/commands/intercept#url-string-glob-regexp",
        "text": "url (String, Glob, RegExp)",
        "level": 4
      },
      {
        "id": "api/commands/intercept#routematcher-routematcher",
        "text": "routeMatcher (RouteMatcher)",
        "level": 4
      },
      {
        "id": "api/commands/intercept#staticresponse-staticresponse-staticresponse-objects",
        "text": "staticResponse ([StaticResponse](#StaticResponse-objects))",
        "level": 4
      },
      {
        "id": "api/commands/intercept#routehandler-function",
        "text": "routeHandler (Function)",
        "level": 4
      },
      {
        "id": "api/commands/intercept#yields-learn-about-subject-management",
        "text": "Yields Learn about subject management",
        "level": 3
      },
      {
        "id": "api/commands/intercept#examples",
        "text": "Examples",
        "level": 2
      },
      {
        "id": "api/commands/intercept#matching-url",
        "text": "Matching url",
        "level": 3
      },
      {
        "id": "api/commands/intercept#matching-method",
        "text": "Matching method",
        "level": 3
      },
      {
        "id": "api/commands/intercept#matching-with-routematcher",
        "text": "Matching with RouteMatcher",
        "level": 3
      },
      {
        "id": "api/commands/intercept#pattern-matching",
        "text": "Pattern Matching",
        "level": 3
      },
      {
        "id": "api/commands/intercept#aliasing-an-intercepted-route",
        "text": "Aliasing an intercepted route",
        "level": 3
      },
      {
        "id": "api/commands/intercept#aliasing-individual-requests",
        "text": "Aliasing individual requests",
        "level": 3
      },
      {
        "id": "api/commands/intercept#waiting-on-a-request",
        "text": "Waiting on a request",
        "level": 3
      },
      {
        "id": "api/commands/intercept#with-url",
        "text": "With URL",
        "level": 4
      },
      {
        "id": "api/commands/intercept#with-routematcher",
        "text": "With RouteMatcher",
        "level": 4
      },
      {
        "id": "api/commands/intercept#using-the-yielded-object",
        "text": "Using the yielded object",
        "level": 4
      },
      {
        "id": "api/commands/intercept#waiting-on-errors",
        "text": "Waiting on errors",
        "level": 4
      },
      {
        "id": "api/commands/intercept#stubbing-a-response",
        "text": "Stubbing a response",
        "level": 3
      },
      {
        "id": "api/commands/intercept#with-a-string",
        "text": "With a string",
        "level": 4
      },
      {
        "id": "api/commands/intercept#with-a-fixture",
        "text": "With a fixture",
        "level": 4
      },
      {
        "id": "api/commands/intercept#with-a-staticresponse-object",
        "text": "With a StaticResponse object",
        "level": 4
      },
      {
        "id": "api/commands/intercept#using-the-routehandler-function",
        "text": "Using the routeHandler function",
        "level": 3
      },
      {
        "id": "api/commands/intercept#asserting-on-a-request",
        "text": "Asserting on a request",
        "level": 4
      },
      {
        "id": "api/commands/intercept#modifying-an-outgoing-request",
        "text": "Modifying an outgoing request",
        "level": 4
      },
      {
        "id": "api/commands/intercept#adding-a-header-to-an-outgoing-request",
        "text": "Adding a header to an outgoing request",
        "level": 4
      },
      {
        "id": "api/commands/intercept#waiting-on-the-intercept",
        "text": "Waiting on the intercept",
        "level": 4
      },
      {
        "id": "api/commands/intercept#add-modify-or-delete-a-header-to-all-outgoing-requests",
        "text": "Add, modify or delete a header to all outgoing requests",
        "level": 4
      },
      {
        "id": "api/commands/intercept#dynamically-stubbing-a-response",
        "text": "Dynamically stubbing a response",
        "level": 4
      },
      {
        "id": "api/commands/intercept#returning-a-promise",
        "text": "Returning a Promise",
        "level": 4
      },
      {
        "id": "api/commands/intercept#passing-a-request-to-the-next-request-handler",
        "text": "Passing a request to the next request handler",
        "level": 4
      },
      {
        "id": "api/commands/intercept#disabling-logs-for-a-request",
        "text": "Disabling logs for a request",
        "level": 3
      },
      {
        "id": "api/commands/intercept#intercepting-a-response",
        "text": "Intercepting a response",
        "level": 3
      },
      {
        "id": "api/commands/intercept#asserting-on-a-response",
        "text": "Asserting on a response",
        "level": 4
      },
      {
        "id": "api/commands/intercept#returning-a-promise",
        "text": "Returning a Promise",
        "level": 4
      },
      {
        "id": "api/commands/intercept#throttle-or-delay-response-all-incoming-responses",
        "text": "Throttle or delay response all incoming responses",
        "level": 4
      },
      {
        "id": "api/commands/intercept#request-response-modification-with-routehandler",
        "text": "Request/Response Modification with routeHandler",
        "level": 3
      },
      {
        "id": "api/commands/intercept#asserting-on-a-request",
        "text": "Asserting on a request",
        "level": 4
      },
      {
        "id": "api/commands/intercept#controlling-the-outgoing-request",
        "text": "Controlling the outgoing request",
        "level": 4
      },
      {
        "id": "api/commands/intercept#verifying-the-request-modification",
        "text": "Verifying the request modification",
        "level": 4
      },
      {
        "id": "api/commands/intercept#controlling-the-response",
        "text": "Controlling the response",
        "level": 4
      },
      {
        "id": "api/commands/intercept#returning-a-promise",
        "text": "Returning a Promise",
        "level": 4
      },
      {
        "id": "api/commands/intercept#stubbing-a-response-with-a-string",
        "text": "Stubbing a response with a string",
        "level": 4
      },
      {
        "id": "api/commands/intercept#intercepted-requests",
        "text": "Intercepted requests",
        "level": 2
      },
      {
        "id": "api/commands/intercept#request-object-properties",
        "text": "Request object properties",
        "level": 3
      },
      {
        "id": "api/commands/intercept#controlling-the-outbound-request-with-req-continue",
        "text": "Controlling the outbound request with req.continue()",
        "level": 3
      },
      {
        "id": "api/commands/intercept#providing-a-stub-response-with-req-reply",
        "text": "Providing a stub response with req.reply()",
        "level": 3
      },
      {
        "id": "api/commands/intercept#req-reply-shorthand",
        "text": "req.reply() shorthand",
        "level": 4
      },
      {
        "id": "api/commands/intercept#convenience-functions",
        "text": "Convenience functions",
        "level": 4
      },
      {
        "id": "api/commands/intercept#request-events",
        "text": "Request events",
        "level": 3
      },
      {
        "id": "api/commands/intercept#intercepted-responses",
        "text": "Intercepted responses",
        "level": 2
      },
      {
        "id": "api/commands/intercept#response-object-properties",
        "text": "Response object properties",
        "level": 3
      },
      {
        "id": "api/commands/intercept#ending-the-response-with-res-send",
        "text": "Ending the response with res.send()",
        "level": 3
      },
      {
        "id": "api/commands/intercept#res-send-shorthand",
        "text": "res.send() shorthand",
        "level": 4
      },
      {
        "id": "api/commands/intercept#convenience-functions",
        "text": "Convenience functions",
        "level": 4
      },
      {
        "id": "api/commands/intercept#staticresponse-objects",
        "text": "StaticResponse objects",
        "level": 2
      },
      {
        "id": "api/commands/intercept#interception-lifecycle",
        "text": "Interception lifecycle",
        "level": 2
      },
      {
        "id": "api/commands/intercept#request-phase",
        "text": "Request phase​",
        "level": 3
      },
      {
        "id": "api/commands/intercept#response-phase",
        "text": "Response phase",
        "level": 3
      },
      {
        "id": "api/commands/intercept#glob-pattern-matching-urls",
        "text": "Glob Pattern Matching URLs",
        "level": 2
      },
      {
        "id": "api/commands/intercept#cypress-minimatch",
        "text": "Cypress.minimatch",
        "level": 3
      },
      {
        "id": "api/commands/intercept#minimatch-options",
        "text": "minimatch options",
        "level": 4
      },
      {
        "id": "api/commands/intercept#cy-intercept-and-request-caching",
        "text": "cy.intercept() and request caching",
        "level": 2
      },
      {
        "id": "api/commands/intercept#command-log",
        "text": "Command Log",
        "level": 2
      },
      {
        "id": "api/commands/intercept#history",
        "text": "History",
        "level": 2
      },
      {
        "id": "api/commands/intercept#see-also",
        "text": "See also",
        "level": 2
      }
    ]
  },
  "chunks": [
    {
      "id": "api/commands/intercept#syntax",
      "doc_id": "api/commands/intercept",
      "heading": "Syntax",
      "heading_level": 2,
      "content_markdown": "## Syntax\n\n```\n// spying onlycy.intercept(url)cy.intercept(method, url)cy.intercept(routeMatcher)\n```\n\nSee arguments [url](#url-String-Glob-RegExp), [method](#method-String) and [routeMatcher](#routeMatcher-RouteMatcher)\n\n```\n// spying and response stubbingcy.intercept(url, staticResponse)cy.intercept(method, url, staticResponse)cy.intercept(routeMatcher, staticResponse)cy.intercept(url, routeMatcher, staticResponse)\n```\n\nSee [staticResponse](#staticResponse-StaticResponse) argument\n\n```\n// spying, dynamic stubbing, request modification, etc.cy.intercept(url, routeHandler)cy.intercept(method, url, routeHandler)cy.intercept(routeMatcher, routeHandler)cy.intercept(url, routeMatcher, routeHandler)\n```\n\nSee [routeHandler](#routeHandler-Function) argument\n\n```\n// Specifying request and response typestype CustomRequest = {  kind: 'custom_request'}type CustomResponse = {  kind: 'custom_response'}cy.intercept<CustomRequest, CustomResponse>(url, (req) => {  req.body // .body of request will be of type CustomRequest  req.continue((res) => {    res.body // .body of response will be of type CustomResponse  })})\n```\n\n### Usage\n\n**Correct Usage**\n\n```\n// spyingcy.intercept('/users/**')cy.intercept('GET', '/users*')cy.intercept({  method: 'GET',  url: '/users*',  hostname: 'localhost',})// spying and response stubbingcy.intercept('POST', '/users*', {  statusCode: 201,  body: {    name: 'Peter Pan',  },})// spying, dynamic stubbing, request modification, etc.cy.intercept('/users*', { hostname: 'localhost' }, (req) => {  /* do something with request and/or response */})\n```\n\n### Arguments\n\n#### **method _(String)_**\n\nMatch the route to a specific [HTTP method](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods) (`GET`, `POST`, `PUT`, etc).\n\nIf no method is defined Cypress will match all requests by default.\n\n#### **url _(String, Glob, RegExp)_**\n\nSpecify the URL to match. See [Matching `url`](#Matching-url) for examples.\n\nAlternatively, specify the URL via the [`routeMatcher`](#routeMatcher-RouteMatcher) argument (below).\n\n#### **routeMatcher _(`RouteMatcher`)_**\n\n`routeMatcher` is an object used to match the incoming HTTP requests with this intercepted route.\n\nAll properties are optional but all those that are set must match for the request to be intercepted. If a `string` is passed to any property, it will be glob-matched against the request using [`Cypress.minimatch`](/llm/markdown/api/utilities/minimatch.md) with the `{ matchBase: true }` minimatch option applied.\n\n| Option | Description |\n| --- | --- |\n| auth | HTTP Basic Authentication (`object` with keys `username` and `password`) |\n| headers | HTTP request headers (`object`) |\n| hostname | HTTP request hostname |\n| https | `true`: only secure (https://) requests, `false`: only insecure (http://) requests |\n| method | HTTP request method (matches any method by default) |\n| middleware | `true`: match route first and in defined order, `false`: match route in reverse order (default) |\n| path | HTTP request path after the hostname, including query parameters |\n| pathname | Like `path`, but without query parameters |\n| port | HTTP request port(s) (`number` or `Array`) |\n| query | Parsed query string (`object`) |\n| resourceType deprecated | The resource type of the request. See [\"Request object properties\"](#Request-object-properties) for a list of possible values for `resourceType`. |\n| times | Maximum number of times to match (`number`) |\n| url | Full HTTP request URL |\n\nSee [examples](#With-RouteMatcher) below.\n\n#### staticResponse (`[StaticResponse](#StaticResponse-objects)`)\n\nBy passing in a `StaticResponse` as the last argument, you can [statically define (stub) a response](#Stubbing-a-response) for matched requests. See [`StaticResponse` object](#StaticResponse-objects) for the list of properties.\n\nAdditionally, you can pass `{ log: false }` with your `StaticResponse` to disable command logs for this intercept. See [\"Disabling logs for a request\"](#Disabling-logs-for-a-request).\n\nSee [Stubbing a response with a `StaticResponse` object](#With-a-StaticResponse-object) for an example.\n\n#### routeHandler (`Function`)\n\nThe `routeHandler` function is called whenever a request is matched, with the first argument being the request object. From inside the callback, you have access to the entire request-response where you can modify the outgoing request, send a response, access the real response, and more.\n\nSee [\"Intercepted requests\"](#Intercepted-requests) and [Request/Response Modification with `routeHandler`](#RequestResponse-Modification-with-routeHandler).\n\n### Yields [Learn about subject management](/llm/markdown/app/core-concepts/introduction-to-cypress.md#Subject-Management)\n\n*   `cy.intercept()` yields `null`, but can be aliased.\n*   Waiting on an aliased `cy.intercept()` route using [cy.wait()](/llm/markdown/api/commands/wait.md) will yield an object that contains information about the matching request/response cycle. See [Using the yielded object](#Using-the-yielded-object) for examples of how to use this object.\n",
      "section": "api",
      "anchors": [
        "syntax"
      ],
      "path": "/llm/json/chunked/api/commands/intercept.json",
      "token_estimate": 796
    },
    {
      "id": "api/commands/intercept#usage",
      "doc_id": "api/commands/intercept",
      "heading": "Usage",
      "heading_level": 3,
      "content_markdown": "### Usage\n\n**Correct Usage**\n\n```\n// spyingcy.intercept('/users/**')cy.intercept('GET', '/users*')cy.intercept({  method: 'GET',  url: '/users*',  hostname: 'localhost',})// spying and response stubbingcy.intercept('POST', '/users*', {  statusCode: 201,  body: {    name: 'Peter Pan',  },})// spying, dynamic stubbing, request modification, etc.cy.intercept('/users*', { hostname: 'localhost' }, (req) => {  /* do something with request and/or response */})\n```\n",
      "section": "api",
      "anchors": [
        "usage"
      ],
      "path": "/llm/json/chunked/api/commands/intercept.json",
      "token_estimate": 67
    },
    {
      "id": "api/commands/intercept#arguments",
      "doc_id": "api/commands/intercept",
      "heading": "Arguments",
      "heading_level": 3,
      "content_markdown": "### Arguments\n\n#### **method _(String)_**\n\nMatch the route to a specific [HTTP method](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods) (`GET`, `POST`, `PUT`, etc).\n\nIf no method is defined Cypress will match all requests by default.\n\n#### **url _(String, Glob, RegExp)_**\n\nSpecify the URL to match. See [Matching `url`](#Matching-url) for examples.\n\nAlternatively, specify the URL via the [`routeMatcher`](#routeMatcher-RouteMatcher) argument (below).\n\n#### **routeMatcher _(`RouteMatcher`)_**\n\n`routeMatcher` is an object used to match the incoming HTTP requests with this intercepted route.\n\nAll properties are optional but all those that are set must match for the request to be intercepted. If a `string` is passed to any property, it will be glob-matched against the request using [`Cypress.minimatch`](/llm/markdown/api/utilities/minimatch.md) with the `{ matchBase: true }` minimatch option applied.\n\n| Option | Description |\n| --- | --- |\n| auth | HTTP Basic Authentication (`object` with keys `username` and `password`) |\n| headers | HTTP request headers (`object`) |\n| hostname | HTTP request hostname |\n| https | `true`: only secure (https://) requests, `false`: only insecure (http://) requests |\n| method | HTTP request method (matches any method by default) |\n| middleware | `true`: match route first and in defined order, `false`: match route in reverse order (default) |\n| path | HTTP request path after the hostname, including query parameters |\n| pathname | Like `path`, but without query parameters |\n| port | HTTP request port(s) (`number` or `Array`) |\n| query | Parsed query string (`object`) |\n| resourceType deprecated | The resource type of the request. See [\"Request object properties\"](#Request-object-properties) for a list of possible values for `resourceType`. |\n| times | Maximum number of times to match (`number`) |\n| url | Full HTTP request URL |\n\nSee [examples](#With-RouteMatcher) below.\n\n#### staticResponse (`[StaticResponse](#StaticResponse-objects)`)\n\nBy passing in a `StaticResponse` as the last argument, you can [statically define (stub) a response](#Stubbing-a-response) for matched requests. See [`StaticResponse` object](#StaticResponse-objects) for the list of properties.\n\nAdditionally, you can pass `{ log: false }` with your `StaticResponse` to disable command logs for this intercept. See [\"Disabling logs for a request\"](#Disabling-logs-for-a-request).\n\nSee [Stubbing a response with a `StaticResponse` object](#With-a-StaticResponse-object) for an example.\n\n#### routeHandler (`Function`)\n\nThe `routeHandler` function is called whenever a request is matched, with the first argument being the request object. From inside the callback, you have access to the entire request-response where you can modify the outgoing request, send a response, access the real response, and more.\n\nSee [\"Intercepted requests\"](#Intercepted-requests) and [Request/Response Modification with `routeHandler`](#RequestResponse-Modification-with-routeHandler).\n",
      "section": "api",
      "anchors": [
        "arguments"
      ],
      "path": "/llm/json/chunked/api/commands/intercept.json",
      "token_estimate": 540
    },
    {
      "id": "api/commands/intercept#routematcher-routematcher",
      "doc_id": "api/commands/intercept",
      "heading": "routeMatcher (RouteMatcher)",
      "heading_level": 4,
      "content_markdown": "#### **routeMatcher _(`RouteMatcher`)_**\n\n`routeMatcher` is an object used to match the incoming HTTP requests with this intercepted route.\n\nAll properties are optional but all those that are set must match for the request to be intercepted. If a `string` is passed to any property, it will be glob-matched against the request using [`Cypress.minimatch`](/llm/markdown/api/utilities/minimatch.md) with the `{ matchBase: true }` minimatch option applied.\n\n| Option | Description |\n| --- | --- |\n| auth | HTTP Basic Authentication (`object` with keys `username` and `password`) |\n| headers | HTTP request headers (`object`) |\n| hostname | HTTP request hostname |\n| https | `true`: only secure (https://) requests, `false`: only insecure (http://) requests |\n| method | HTTP request method (matches any method by default) |\n| middleware | `true`: match route first and in defined order, `false`: match route in reverse order (default) |\n| path | HTTP request path after the hostname, including query parameters |\n| pathname | Like `path`, but without query parameters |\n| port | HTTP request port(s) (`number` or `Array`) |\n| query | Parsed query string (`object`) |\n| resourceType deprecated | The resource type of the request. See [\"Request object properties\"](#Request-object-properties) for a list of possible values for `resourceType`. |\n| times | Maximum number of times to match (`number`) |\n| url | Full HTTP request URL |\n\nSee [examples](#With-RouteMatcher) below.\n",
      "section": "api",
      "anchors": [
        "routematcher-routematcher"
      ],
      "path": "/llm/json/chunked/api/commands/intercept.json",
      "token_estimate": 308
    },
    {
      "id": "api/commands/intercept#staticresponse-staticresponse-staticresponse-objects",
      "doc_id": "api/commands/intercept",
      "heading": "staticResponse ([StaticResponse](#StaticResponse-objects))",
      "heading_level": 4,
      "content_markdown": "#### staticResponse (`[StaticResponse](#StaticResponse-objects)`)\n\nBy passing in a `StaticResponse` as the last argument, you can [statically define (stub) a response](#Stubbing-a-response) for matched requests. See [`StaticResponse` object](#StaticResponse-objects) for the list of properties.\n\nAdditionally, you can pass `{ log: false }` with your `StaticResponse` to disable command logs for this intercept. See [\"Disabling logs for a request\"](#Disabling-logs-for-a-request).\n\nSee [Stubbing a response with a `StaticResponse` object](#With-a-StaticResponse-object) for an example.\n",
      "section": "api",
      "anchors": [
        "staticresponse-staticresponse-staticresponse-objects"
      ],
      "path": "/llm/json/chunked/api/commands/intercept.json",
      "token_estimate": 87
    },
    {
      "id": "api/commands/intercept#routehandler-function",
      "doc_id": "api/commands/intercept",
      "heading": "routeHandler (Function)",
      "heading_level": 4,
      "content_markdown": "#### routeHandler (`Function`)\n\nThe `routeHandler` function is called whenever a request is matched, with the first argument being the request object. From inside the callback, you have access to the entire request-response where you can modify the outgoing request, send a response, access the real response, and more.\n\nSee [\"Intercepted requests\"](#Intercepted-requests) and [Request/Response Modification with `routeHandler`](#RequestResponse-Modification-with-routeHandler).\n",
      "section": "api",
      "anchors": [
        "routehandler-function"
      ],
      "path": "/llm/json/chunked/api/commands/intercept.json",
      "token_estimate": 75
    },
    {
      "id": "api/commands/intercept#yields-learn-about-subject-management",
      "doc_id": "api/commands/intercept",
      "heading": "Yields Learn about subject management",
      "heading_level": 3,
      "content_markdown": "### Yields [Learn about subject management](/llm/markdown/app/core-concepts/introduction-to-cypress.md#Subject-Management)\n\n*   `cy.intercept()` yields `null`, but can be aliased.\n*   Waiting on an aliased `cy.intercept()` route using [cy.wait()](/llm/markdown/api/commands/wait.md) will yield an object that contains information about the matching request/response cycle. See [Using the yielded object](#Using-the-yielded-object) for examples of how to use this object.\n",
      "section": "api",
      "anchors": [
        "yields-learn-about-subject-management"
      ],
      "path": "/llm/json/chunked/api/commands/intercept.json",
      "token_estimate": 64
    },
    {
      "id": "api/commands/intercept#examples",
      "doc_id": "api/commands/intercept",
      "heading": "Examples",
      "heading_level": 2,
      "content_markdown": "## Examples\n\n`cy.intercept` can be used solely for spying: to passively listen for matching routes and apply [aliases](#Aliasing-an-intercepted-route) to them without manipulating the request or its response in any way. This alone is powerful as it allows you to [wait](#Waiting-on-a-request) for these requests, resulting in more reliable tests.\n\n### Matching `url`\n\nYou can provide the exact [URL](#Arguments) to match or use pattern-matching to match many URLs at once, either with globs or with regex. See [Glob Pattern Matching URLs](#Glob-Pattern-Matching-URLs).\n\n```\n// match any request that exactly matches the URLcy.intercept('https://prod.cypress.io/users')// match any request that satisfies a glob patterncy.intercept('/users?_limit=*')// match any request that satisfies a regex patterncy.intercept(/\\/users\\?_limit=(3|5)$/)\n```\n\n### Matching `method`\n\nIf you don't pass in a [`method` argument](#method-String), then all HTTP methods (`GET`, `POST`, `PUT`, `PATCH`, `DELETE`, etc.) will match.\n\n```\ncy.intercept('/users')// matches this: GET http://localhost/users// ...and this, too: POST http://localhost/userscy.intercept('GET', '/users')// matches this: GET http://localhost/users// ...but not this: POST http://localhost/users\n```\n\n### Matching with [RouteMatcher](#routeMatcher-RouteMatcher)\n\nSpecifying a `method` and `url` to match can also be acheived by passing the `routeMatcher` object into `cy.intercept` instead:\n\n```\n// These both yield the same result:cy.intercept({ method: 'GET', url: '**/users' })cy.intercept('GET', '**/users')\n```\n\n```\n// Match any type of request with the pathname `/search`// and the query parameter 'q=some+terms'cy.intercept({  pathname: '/search',  query: {    q: 'some terms',  },}).as('searchForTerms')\n```\n\n```\ncy.intercept(  {    // this RegExp matches any URL beginning with    // 'http://api.example.com/' and ending with '/edit' or '/save'    url: /^http:\\/\\/api\\.example\\.com\\/.*\\/(edit|save)/,    // matching requests must also contain this header    headers: {      'x-requested-with': 'exampleClient',    },  }})\n```\n\n```\n// this example will cause 1 request to `/temporary-error`// to receive a network error and subsequent requests will// not match this `RouteMatcher`cy.intercept({ url: '/temporary-error', times: 1 }, { forceNetworkError: true })\n```\n\n### Pattern Matching\n\n```\n// match updates to the `/users` endpoint using glob matchingcy.intercept({  method: '+(PUT|PATCH)',  url: '**/users/*',})// matches://   PUT /users/1//   PATCH /users/1//// doesn't match://   GET /users//   GET /users/1// same as above, but using regexcy.intercept({  method: '/PUT|PATCH/',  url: '**/users/*',})\n```\n\n### Aliasing an intercepted route\n\nWhile `cy.intercept` doesn't yield anything, you can chain [`.as`](/llm/markdown/api/commands/as.md) to it to create an [alias](/llm/markdown/app/core-concepts/variables-and-aliases.md#Aliases) which can be used to [wait on a request](#Waiting-on-a-request).\n\n```\ncy.intercept('GET', '/users').as('getAllUsers')cy.intercept('POST', '/users').as('createUser')\n```\n\n### Aliasing individual requests\n\nAliases can be set on a per-request basis by setting the `alias` property of the intercepted request. This is especially useful when intercepting GraphQL requests:\n\n```\ncy.intercept('POST', '/graphql', (req) => {  if (req.body.hasOwnProperty('query') && req.body.query.includes('mutation')) {    req.alias = 'gqlMutation'  }})// assert that a matching request has been madecy.wait('@gqlMutation')\n```\n\nFor more guidance around aliasing requests with GraphQL, see [Working with GraphQL](/llm/markdown/app/guides/network-requests.md#Working-with-GraphQL).\n\n### Waiting on a request\n\nUse [cy.wait()](/llm/markdown/api/commands/wait.md) with [aliasing an intercepted route](#Aliasing-an-intercepted-route) to wait for the request/response cycle to complete.\n\n#### With URL\n\n```\ncy.intercept('http://example.com/settings').as('getSettings')// once a request to get settings responds, 'cy.wait' will resolvecy.wait('@getSettings')\n```\n\n#### With [RouteMatcher](#routeMatcher-RouteMatcher)\n\n```\ncy.intercept({  url: 'http://example.com/search*',  query: { q: 'expected terms' },}).as('search')// once any type of request to search with a querystring// containing 'q=expected+terms' responds, 'cy.wait' will resolvecy.wait('@search')\n```\n\n#### Using the yielded object\n\nUsing [cy.wait()](/llm/markdown/api/commands/wait.md) on a `cy.intercept()` route alias yields an interception object which represents the request/response cycle:\n\n```\ncy.wait('@someRoute').then((interception) => {  // 'interception' is an object with properties  // 'id', 'request' and 'response'})\n```\n\nYou can chain [`.its()`](/llm/markdown/api/commands/its.md) and [`.should()`](/llm/markdown/api/commands/should.md) to assert against request/response cycles:\n\n```\n// assert that a request to this route// was made with a body that included 'user'cy.wait('@someRoute').its('request.body').should('include', 'user')// assert that a request to this route// received a response with HTTP status 500cy.wait('@someRoute').its('response.statusCode').should('eq', 500)// assert that a request to this route// received a response body that includes 'id'cy.wait('@someRoute').its('response.body').should('include', 'id')\n```\n\n#### Waiting on errors\n\nYou can use [cy.wait()](/llm/markdown/api/commands/wait.md) to wait on requests that end with network errors:\n\n```\ncy.intercept('GET', '/should-err', { forceNetworkError: true }).as('err')// assert that this request happened// and that it ended in an errorcy.wait('@err').should('have.property', 'error')\n```\n\n### Stubbing a response\n\n#### With a string\n\n```\n// requests to '/update' will be fulfilled// with a body of \"success\"cy.intercept('/update', 'success')\n```\n\n#### With a fixture\n\n```\n// requests to '/users.json' will be fulfilled// with the contents of the \"users.json\" fixturecy.intercept('/users.json', { fixture: 'users.json' })\n```\n\n#### With a `StaticResponse` object\n\nA [`StaticResponse`](#StaticResponse-objects) object represents a response to an HTTP request, and can be used to stub routes:\n\n```\nconst staticResponse = {  /* some StaticResponse properties here... */}cy.intercept('/projects', staticResponse)\n```\n\nStub a response with a JSON body:\n\n```\ncy.intercept('/projects', {  body: [{ projectId: '1' }, { projectId: '2' }],})\n```\n\nStub headers, status code, and body all at once:\n\n```\ncy.intercept('/not-found', {  statusCode: 404,  body: '404 Not Found!',  headers: {    'x-not-found': 'true',  },})\n```\n\nStub response with a fixture that is read as a Buffer:\n\n```\ncy.intercept('/not-found', {  fixture: 'media/gif.mp4,null',})\n```\n\nSee also [`StaticResponse` object](#StaticResponse-objects).\n\n### Using the **`routeHandler`** function\n\nBy specifying a [`routeHandler`](#routeHandler-Function) function as the last argument to `cy.intercept`, you'll have access to the entire request-response session, enabling you to modify the outgoing request, manipulate the real response, make assertions, etc.\n\nThe `routeHandler` takes the incoming HTTP request (`IncomingHTTPRequest`) as the first argument.\n\n```\ncy.intercept('/users*', (req) => {  /* do something with request and/or response */})\n```\n\nThroughout these examples we will refer to the incoming HTTP request as `req`. Those of you with [Express.js](https://expressjs.com/) [middleware](https://expressjs.com/en/guide/writing-middleware.html) experience should be familiar with this syntax.\n\n#### Asserting on a request\n\n```\ncy.intercept('POST', '/organization', (req) => {  expect(req.body).to.include('Acme Company')})\n```\n\n#### Modifying an outgoing request\n\nYou can use the request handler callback to modify the [intercepted request object](#Intercepted-requests) before it is sent.\n\n```\n// set the request body to something different// before it's sent to the destinationcy.intercept('POST', '/login', (req) => {  req.body = 'username=janelane&password=secret123'})// dynamically set the aliascy.intercept('POST', '/login', (req) => {  req.alias = 'login'})\n```\n\n#### Adding a header to an outgoing request\n\nYou can add a header to an outgoing request, or modify an existing header\n\n```\ncy.intercept('/req-headers', (req) => {  req.headers['x-custom-headers'] = 'added by cy.intercept'})\n```\n\n**Note:** the new header will NOT be shown in the browser's Network tab, as the request has already left the browser. You can still confirm the header was added by waiting on the intercept as shown below:\n\n#### Waiting on the intercept\n\n```\ncy.intercept('/req-headers', (req) => {  req.headers['x-custom-headers'] = 'added by cy.intercept'}).as('headers')// the application makes the call ...// confirm the custom header was addedcy.wait('@headers')  .its('request.headers')  .should('have.property', 'x-custom-headers', 'added by cy.intercept')\n```\n\n#### Add, modify or delete a header to all outgoing requests\n\nYou can add, modify or delete a header to all outgoing requests using a `beforeEach()` in the [supportFile](/llm/markdown/app/core-concepts/writing-and-organizing-tests.md#Support-file).\n\n```\nbeforeEach(() => {  cy.intercept(    { url: 'http://localhost:3001/**', middleware: true },    // Delete 'if-none-match' header from all outgoing requests    (req) => delete req.headers['if-none-match']  )})\n```\n\n#### Dynamically stubbing a response\n\nYou can use the [`req.reply()`](#Providing-a-stub-response-with-reqreply) function to dynamically control the response to a request.\n\n```\ncy.intercept('/billing', (req) => {  // functions on 'req' can be used to  // dynamically respond to a request here  // send the request to the destination server  req.reply()  // respond to the request with a JSON object  req.reply({ plan: 'starter' })  // send the request to the destination server  // and intercept the response  req.continue((res) => {    // 'res' represents the real destination's response    // See \"Intercepting a response\" for more details and examples  })})\n```\n\nSee [\"Intercepted requests\"](#Intercepted-requests) for more information on the `req` object and its properties and methods.\n\n#### Returning a Promise\n\nIf a Promise is returned from the route callback, it will be awaited before continuing with the request.\n\n```\ncy.intercept('POST', '/login', (req) => {  // you could asynchronously fetch test data...  return getLoginCredentials().then((credentials) => {    // ...and then, use it to supplement the outgoing request    req.headers['authorization'] = credentials  })})\n```\n\n#### Passing a request to the next request handler\n\nIf [`req.reply()`](#Providing-a-stub-response-with-reqreply) or [`req.continue()`](#Controlling-the-outbound-request-with-reqcontinue) is not explicitly called inside of a request handler, requests will pass to the next request handler until none are left.\n\n```\n// you could have a top-level middleware handler that// sets an auth token on all requests// but remember setting `middleware: true` will// cause this to always be called firstcy.intercept('http://api.company.com/', { middleware: true }, (req) => {  req.headers['authorization'] = `token ${token}`})// and then have another handler that// more narrowly asserts on certain requestscy.intercept('POST', 'http://api.company.com/widgets', (req) => {  expect(req.body).to.include('analytics')})// a POST request to http://api.company.com/widgets would hit both// of those callbacks, middleware first, then the request would be// sent out with the modified request headers to the// real destination\n```\n\n### Disabling logs for a request\n\nBy default, Cypress logs all requests that match any `cy.intercept()`, as well as all `XMLHttpRequest`s and `fetch` requests. You can use `cy.intercept()` to disable these logs by passing `{ log: false }` in the second parameter:\n\n```\n// disable Cypress's default behavior of logging all XMLHttpRequests and fetchescy.intercept({ resourceType: /xhr|fetch/ }, { log: false })\n```\n\nNote: Currently, you can only enable/disable a request's logs when defining the `cy.intercept()`, not inside of an `intercept` callback. See [#26069](https://github.com/cypress-io/cypress/issues/26069).\n\n### Intercepting a response\n\nInside of a callback passed to `req.continue()`, you can access the destination server's real response.\n\n```\ncy.intercept('/integrations', (req) => {  // req.continue() with a callback will send the request to  // the destination server  req.continue((res) => {    // 'res' represents the real destination response    // you can manipulate 'res' before it's sent to the browser  })})\n```\n\nSee [\"Intercepted responses\"](#Intercepted-responses) for more information on the `res` object. See [\"Controlling the outbound request with `req.continue()`\"](#Controlling-the-outbound-request-with-reqcontinue) for more information about `req.continue()`.\n\n#### Asserting on a response\n\n```\ncy.intercept('/projects/2', (req) => {  req.continue((res) => {    expect(res.body).to.include('My Project')  })})\n```\n\n#### Returning a Promise\n\nIf a Promise is returned from the route callback, it will be awaited before sending the response to the browser.\n\n```\ncy.intercept('/users', (req) => {  req.continue((res) => {    // the response will not be sent to the browser until    // 'waitForSomething()' resolves    return waitForSomething()  })})\n```\n\n#### Throttle or delay response all incoming responses\n\nYou can throttle or delay all incoming responses using a `beforeEach()` in the [supportFile](/llm/markdown/app/core-concepts/writing-and-organizing-tests.md#Support-file).\n\n```\n// Throttle API responses to simulate real-world conditionsbeforeEach(() => {  cy.intercept(    {      url: 'http://localhost:3001/**',      middleware: true,    },    (req) => {      req.on('response', (res) => {        // Throttle the response to 1 Mbps to simulate a        // mobile 3G connection        res.setThrottle(1000)      })    }  )})\n```\n\n### Request/Response Modification with `routeHandler`\n\nSpecify [`routeHandler`](#routeHandler-Function) as the last argument to modify the outgoing request, stub a response, make assertions, etc.\n\nIf a function is passed as the `routeHandler`, it will be called with the intercepted HTTP request:\n\n```\ncy.intercept('/api', (req) => {  // do something with the intercepted request})\n```\n\nFrom here, you can do several things with the intercepted request:\n\n*   modify and make assertions on the request like its body, headers, URL, method, etc. ([example](#Asserting-on-a-request-1))\n*   stub out the response without interacting with a real back-end ([example](#Controlling-the-response)\n*   pass the request through to its destination and modify or make assertions on the real response on its way back ([example](#Controlling-the-response))\n*   attach listeners to various events on the request ([example](#Controlling-the-response))\n\n#### Asserting on a request\n\nYou can use the request handler callback to make an assertion on the [intercepted request object](#Intercepted-requests) before it is sent.\n\n```\n// match requests to create a usercy.intercept('POST', '/users', (req) => {  // make an assertion on the payload contents  expect(req.body).to.include('Peter Pan')})\n```\n\n#### Controlling the outgoing request\n\nThe outgoing request, including its body, headers, etc., can be modified before it's sent.\n\n```\n// modify the request body before it's sent to its destinationcy.intercept('POST', '/users', (req) => {  req.body = {    name: 'Peter Pan',  }})// add a header to an outgoing requestcy.intercept('POST', '/users', (req) => {  req.headers['x-custom-header'] = 'added by cy.intercept'})// modify an existing headercy.intercept('POST', '/users', (req) => {  req.headers['authorization'] = 'Basic YWxhZGRpbjpvcGVuc2VzYW1l'})\n```\n\n#### Verifying the request modification\n\n```\ncy.intercept('POST', '/users', (req) => {  req.headers['x-custom-header'] = 'added by cy.intercept'}).as('createUser')cy.get('button.save').click()// you can see the headers in the console output by selecting// this line in the command log:cy.wait('@createUser')  // ...or make an assertion:  .its('request.headers')  .should('have.property', 'x-custom-header', 'added by cy.intercept')\n```\n\nThe request modification cannot be verified by inspecting the browser's network traffic (for example, in Chrome DevTools), since the browser logs network traffic _before_ Cypress can intercept it.\n\n`cy.intercept()` cannot be debugged using [`cy.request()`](/llm/markdown/api/commands/request.md)! Cypress only intercepts requests made by your front-end application.\n\n#### Controlling the response\n\nThe intercepted request passed to the route handler (hereafter referred to as `req`, though you can use any name) contains methods to dynamically control the response to a request:\n\n*   `req.reply()` - stub out a response requiring no dependency on a real back-end\n*   `req.continue()` - modify or make assertions on the real response\n*   `req.destroy()` - destroy the request and respond with a network error\n*   `req.redirect()` - respond to the request with a redirect to a specified location\n*   `req.on()` - modify the response by attaching to events\n\nStubbing out a response (`req.reply()`):\n\n`req.reply()` takes a [`StaticResponse`](#StaticResponse-objects) object as the first argument:\n\n```\n// stub out the response without interacting with a real back-endcy.intercept('POST', '/users', (req) => {  req.reply({    headers: {      Set-Cookie: 'newUserName=Peter Pan;'    },    statusCode: 201,    body: {      name: 'Peter Pan'    },    delay: 10, // milliseconds    throttleKbps: 1000, // to simulate a 3G connection    forceNetworkError: false // default  })})// stub out a response body using a fixturecy.intercept('GET', '/users', (req) => {  req.reply({    statusCode: 200, // default    fixture: 'users.json'  })})\n```\n\nSee [`StaticResponse` objects](#StaticResponse-objects) below for more information.\n\nThe `reply` method also supports shorthand to avoid having to specify a `StaticResponse` object:\n\n```\n// equivalent to `req.reply({ body })`req.reply(body)// equivalent to `req.reply({ body, headers })`req.reply(body, headers)// equivalent to `req.reply({ statusCode, body, headers})`req.reply(statusCode, body, headers)\n```\n\nNote: Calling `reply()` will end the request phase and stop the request from propagating to the next matching request handler in line. See [Interception Lifecycle](#Interception-lifecycle).\n\nSee also [Providing a stub response with `req.reply()`](#Providing-a-stub-response-with-reqreply)\n\nModifying the real response (`continue`):\n\nThe `continue` method accepts a function which is passed an object representing the real response being intercepted on its way back to the client (your front-end application).\n\n```\n// pass the request through and make an assertion on// the real responsecy.intercept('POST', '/users', (req) => {  req.continue((res) => {    expect(res.body).to.include('Peter Pan')  })})\n```\n\nSee also [Controlling the outbound request with `req.continue()`](#Controlling-the-outbound-request-with-reqcontinue)\n\nResponding with a network error (`destroy`):\n\n```\n// dynamically destroy the request and// respond with a network errorcy.intercept('POST', '/users', (req) => {  if (mustDestroy(req)) {    req.destroy()  }  function mustDestroy(req) {    // code that determines whether to force a network error    // based on the contents of `req`  }})\n```\n\nResponding with a new location (`redirect`):\n\n```\n// respond to this request with a redirect to a new 'location'cy.intercept('GET', '/users', (req) => {  // statusCode defaults to `302`  req.redirect('/customers', 301)})\n```\n\nResponding by listening to events (`on`):\n\n```\ncy.intercept('GET', '/users', (req) => {  req.on('before:response', (res) => {    // do something when the `before:response` event is triggered  })})cy.intercept('POST', '/users', (req) => {  req.on('response', (res) => {    // do something when the `response` event is triggered  })})\n```\n\nSee example for [throttling a response](#Throttle-or-delay-response-all-incoming-responses) See more examples of [events](#Request-events)\n\n#### Returning a Promise\n\nIf a Promise is returned from the route callback, it will be awaited before continuing with the request.\n\n```\ncy.intercept('POST', '/users', (req) => {  // asynchronously fetch test data  return getAuthToken().then((token) => {    // ...and apply it to the outgoing request    req.headers['Authorization'] = `Basic ${token}`  })})cy.intercept('POST', '/users', (req) => {  req.continue((res) => {    // the response will not be sent to the browser until    // `waitForSomething()` resolves:    return waitForSomething()  })})\n```\n\n#### Stubbing a response with a string\n\n```\n// requests to create a user will be fulfilled// with a body of 'success'cy.intercept('POST', '/users', 'success')// { body: 'success' }\n```\n",
      "section": "api",
      "anchors": [
        "examples"
      ],
      "path": "/llm/json/chunked/api/commands/intercept.json",
      "token_estimate": 3419
    },
    {
      "id": "api/commands/intercept#matching-url",
      "doc_id": "api/commands/intercept",
      "heading": "Matching url",
      "heading_level": 3,
      "content_markdown": "### Matching `url`\n\nYou can provide the exact [URL](#Arguments) to match or use pattern-matching to match many URLs at once, either with globs or with regex. See [Glob Pattern Matching URLs](#Glob-Pattern-Matching-URLs).\n\n```\n// match any request that exactly matches the URLcy.intercept('https://prod.cypress.io/users')// match any request that satisfies a glob patterncy.intercept('/users?_limit=*')// match any request that satisfies a regex patterncy.intercept(/\\/users\\?_limit=(3|5)$/)\n```\n",
      "section": "api",
      "anchors": [
        "matching-url"
      ],
      "path": "/llm/json/chunked/api/commands/intercept.json",
      "token_estimate": 77
    },
    {
      "id": "api/commands/intercept#matching-method",
      "doc_id": "api/commands/intercept",
      "heading": "Matching method",
      "heading_level": 3,
      "content_markdown": "### Matching `method`\n\nIf you don't pass in a [`method` argument](#method-String), then all HTTP methods (`GET`, `POST`, `PUT`, `PATCH`, `DELETE`, etc.) will match.\n\n```\ncy.intercept('/users')// matches this: GET http://localhost/users// ...and this, too: POST http://localhost/userscy.intercept('GET', '/users')// matches this: GET http://localhost/users// ...but not this: POST http://localhost/users\n```\n",
      "section": "api",
      "anchors": [
        "matching-method"
      ],
      "path": "/llm/json/chunked/api/commands/intercept.json",
      "token_estimate": 60
    },
    {
      "id": "api/commands/intercept#matching-with-routematcher",
      "doc_id": "api/commands/intercept",
      "heading": "Matching with RouteMatcher",
      "heading_level": 3,
      "content_markdown": "### Matching with [RouteMatcher](#routeMatcher-RouteMatcher)\n\nSpecifying a `method` and `url` to match can also be acheived by passing the `routeMatcher` object into `cy.intercept` instead:\n\n```\n// These both yield the same result:cy.intercept({ method: 'GET', url: '**/users' })cy.intercept('GET', '**/users')\n```\n\n```\n// Match any type of request with the pathname `/search`// and the query parameter 'q=some+terms'cy.intercept({  pathname: '/search',  query: {    q: 'some terms',  },}).as('searchForTerms')\n```\n\n```\ncy.intercept(  {    // this RegExp matches any URL beginning with    // 'http://api.example.com/' and ending with '/edit' or '/save'    url: /^http:\\/\\/api\\.example\\.com\\/.*\\/(edit|save)/,    // matching requests must also contain this header    headers: {      'x-requested-with': 'exampleClient',    },  }})\n```\n\n```\n// this example will cause 1 request to `/temporary-error`// to receive a network error and subsequent requests will// not match this `RouteMatcher`cy.intercept({ url: '/temporary-error', times: 1 }, { forceNetworkError: true })\n```\n",
      "section": "api",
      "anchors": [
        "matching-with-routematcher"
      ],
      "path": "/llm/json/chunked/api/commands/intercept.json",
      "token_estimate": 176
    },
    {
      "id": "api/commands/intercept#pattern-matching",
      "doc_id": "api/commands/intercept",
      "heading": "Pattern Matching",
      "heading_level": 3,
      "content_markdown": "### Pattern Matching\n\n```\n// match updates to the `/users` endpoint using glob matchingcy.intercept({  method: '+(PUT|PATCH)',  url: '**/users/*',})// matches://   PUT /users/1//   PATCH /users/1//// doesn't match://   GET /users//   GET /users/1// same as above, but using regexcy.intercept({  method: '/PUT|PATCH/',  url: '**/users/*',})\n```\n",
      "section": "api",
      "anchors": [
        "pattern-matching"
      ],
      "path": "/llm/json/chunked/api/commands/intercept.json",
      "token_estimate": 53
    },
    {
      "id": "api/commands/intercept#aliasing-an-intercepted-route",
      "doc_id": "api/commands/intercept",
      "heading": "Aliasing an intercepted route",
      "heading_level": 3,
      "content_markdown": "### Aliasing an intercepted route\n\nWhile `cy.intercept` doesn't yield anything, you can chain [`.as`](/llm/markdown/api/commands/as.md) to it to create an [alias](/llm/markdown/app/core-concepts/variables-and-aliases.md#Aliases) which can be used to [wait on a request](#Waiting-on-a-request).\n\n```\ncy.intercept('GET', '/users').as('getAllUsers')cy.intercept('POST', '/users').as('createUser')\n```\n",
      "section": "api",
      "anchors": [
        "aliasing-an-intercepted-route"
      ],
      "path": "/llm/json/chunked/api/commands/intercept.json",
      "token_estimate": 45
    },
    {
      "id": "api/commands/intercept#aliasing-individual-requests",
      "doc_id": "api/commands/intercept",
      "heading": "Aliasing individual requests",
      "heading_level": 3,
      "content_markdown": "### Aliasing individual requests\n\nAliases can be set on a per-request basis by setting the `alias` property of the intercepted request. This is especially useful when intercepting GraphQL requests:\n\n```\ncy.intercept('POST', '/graphql', (req) => {  if (req.body.hasOwnProperty('query') && req.body.query.includes('mutation')) {    req.alias = 'gqlMutation'  }})// assert that a matching request has been madecy.wait('@gqlMutation')\n```\n\nFor more guidance around aliasing requests with GraphQL, see [Working with GraphQL](/llm/markdown/app/guides/network-requests.md#Working-with-GraphQL).\n",
      "section": "api",
      "anchors": [
        "aliasing-individual-requests"
      ],
      "path": "/llm/json/chunked/api/commands/intercept.json",
      "token_estimate": 87
    },
    {
      "id": "api/commands/intercept#waiting-on-a-request",
      "doc_id": "api/commands/intercept",
      "heading": "Waiting on a request",
      "heading_level": 3,
      "content_markdown": "### Waiting on a request\n\nUse [cy.wait()](/llm/markdown/api/commands/wait.md) with [aliasing an intercepted route](#Aliasing-an-intercepted-route) to wait for the request/response cycle to complete.\n\n#### With URL\n\n```\ncy.intercept('http://example.com/settings').as('getSettings')// once a request to get settings responds, 'cy.wait' will resolvecy.wait('@getSettings')\n```\n\n#### With [RouteMatcher](#routeMatcher-RouteMatcher)\n\n```\ncy.intercept({  url: 'http://example.com/search*',  query: { q: 'expected terms' },}).as('search')// once any type of request to search with a querystring// containing 'q=expected+terms' responds, 'cy.wait' will resolvecy.wait('@search')\n```\n\n#### Using the yielded object\n\nUsing [cy.wait()](/llm/markdown/api/commands/wait.md) on a `cy.intercept()` route alias yields an interception object which represents the request/response cycle:\n\n```\ncy.wait('@someRoute').then((interception) => {  // 'interception' is an object with properties  // 'id', 'request' and 'response'})\n```\n\nYou can chain [`.its()`](/llm/markdown/api/commands/its.md) and [`.should()`](/llm/markdown/api/commands/should.md) to assert against request/response cycles:\n\n```\n// assert that a request to this route// was made with a body that included 'user'cy.wait('@someRoute').its('request.body').should('include', 'user')// assert that a request to this route// received a response with HTTP status 500cy.wait('@someRoute').its('response.statusCode').should('eq', 500)// assert that a request to this route// received a response body that includes 'id'cy.wait('@someRoute').its('response.body').should('include', 'id')\n```\n\n#### Waiting on errors\n\nYou can use [cy.wait()](/llm/markdown/api/commands/wait.md) to wait on requests that end with network errors:\n\n```\ncy.intercept('GET', '/should-err', { forceNetworkError: true }).as('err')// assert that this request happened// and that it ended in an errorcy.wait('@err').should('have.property', 'error')\n```\n",
      "section": "api",
      "anchors": [
        "waiting-on-a-request"
      ],
      "path": "/llm/json/chunked/api/commands/intercept.json",
      "token_estimate": 269
    },
    {
      "id": "api/commands/intercept#with-routematcher",
      "doc_id": "api/commands/intercept",
      "heading": "With RouteMatcher",
      "heading_level": 4,
      "content_markdown": "#### With [RouteMatcher](#routeMatcher-RouteMatcher)\n\n```\ncy.intercept({  url: 'http://example.com/search*',  query: { q: 'expected terms' },}).as('search')// once any type of request to search with a querystring// containing 'q=expected+terms' responds, 'cy.wait' will resolvecy.wait('@search')\n```\n",
      "section": "api",
      "anchors": [
        "with-routematcher"
      ],
      "path": "/llm/json/chunked/api/commands/intercept.json",
      "token_estimate": 40
    },
    {
      "id": "api/commands/intercept#using-the-yielded-object",
      "doc_id": "api/commands/intercept",
      "heading": "Using the yielded object",
      "heading_level": 4,
      "content_markdown": "#### Using the yielded object\n\nUsing [cy.wait()](/llm/markdown/api/commands/wait.md) on a `cy.intercept()` route alias yields an interception object which represents the request/response cycle:\n\n```\ncy.wait('@someRoute').then((interception) => {  // 'interception' is an object with properties  // 'id', 'request' and 'response'})\n```\n\nYou can chain [`.its()`](/llm/markdown/api/commands/its.md) and [`.should()`](/llm/markdown/api/commands/should.md) to assert against request/response cycles:\n\n```\n// assert that a request to this route// was made with a body that included 'user'cy.wait('@someRoute').its('request.body').should('include', 'user')// assert that a request to this route// received a response with HTTP status 500cy.wait('@someRoute').its('response.statusCode').should('eq', 500)// assert that a request to this route// received a response body that includes 'id'cy.wait('@someRoute').its('response.body').should('include', 'id')\n```\n",
      "section": "api",
      "anchors": [
        "using-the-yielded-object"
      ],
      "path": "/llm/json/chunked/api/commands/intercept.json",
      "token_estimate": 131
    },
    {
      "id": "api/commands/intercept#waiting-on-errors",
      "doc_id": "api/commands/intercept",
      "heading": "Waiting on errors",
      "heading_level": 4,
      "content_markdown": "#### Waiting on errors\n\nYou can use [cy.wait()](/llm/markdown/api/commands/wait.md) to wait on requests that end with network errors:\n\n```\ncy.intercept('GET', '/should-err', { forceNetworkError: true }).as('err')// assert that this request happened// and that it ended in an errorcy.wait('@err').should('have.property', 'error')\n```\n",
      "section": "api",
      "anchors": [
        "waiting-on-errors"
      ],
      "path": "/llm/json/chunked/api/commands/intercept.json",
      "token_estimate": 51
    },
    {
      "id": "api/commands/intercept#stubbing-a-response",
      "doc_id": "api/commands/intercept",
      "heading": "Stubbing a response",
      "heading_level": 3,
      "content_markdown": "### Stubbing a response\n\n#### With a string\n\n```\n// requests to '/update' will be fulfilled// with a body of \"success\"cy.intercept('/update', 'success')\n```\n\n#### With a fixture\n\n```\n// requests to '/users.json' will be fulfilled// with the contents of the \"users.json\" fixturecy.intercept('/users.json', { fixture: 'users.json' })\n```\n\n#### With a `StaticResponse` object\n\nA [`StaticResponse`](#StaticResponse-objects) object represents a response to an HTTP request, and can be used to stub routes:\n\n```\nconst staticResponse = {  /* some StaticResponse properties here... */}cy.intercept('/projects', staticResponse)\n```\n\nStub a response with a JSON body:\n\n```\ncy.intercept('/projects', {  body: [{ projectId: '1' }, { projectId: '2' }],})\n```\n\nStub headers, status code, and body all at once:\n\n```\ncy.intercept('/not-found', {  statusCode: 404,  body: '404 Not Found!',  headers: {    'x-not-found': 'true',  },})\n```\n\nStub response with a fixture that is read as a Buffer:\n\n```\ncy.intercept('/not-found', {  fixture: 'media/gif.mp4,null',})\n```\n\nSee also [`StaticResponse` object](#StaticResponse-objects).\n",
      "section": "api",
      "anchors": [
        "stubbing-a-response"
      ],
      "path": "/llm/json/chunked/api/commands/intercept.json",
      "token_estimate": 196
    },
    {
      "id": "api/commands/intercept#with-a-staticresponse-object",
      "doc_id": "api/commands/intercept",
      "heading": "With a StaticResponse object",
      "heading_level": 4,
      "content_markdown": "#### With a `StaticResponse` object\n\nA [`StaticResponse`](#StaticResponse-objects) object represents a response to an HTTP request, and can be used to stub routes:\n\n```\nconst staticResponse = {  /* some StaticResponse properties here... */}cy.intercept('/projects', staticResponse)\n```\n\nStub a response with a JSON body:\n\n```\ncy.intercept('/projects', {  body: [{ projectId: '1' }, { projectId: '2' }],})\n```\n\nStub headers, status code, and body all at once:\n\n```\ncy.intercept('/not-found', {  statusCode: 404,  body: '404 Not Found!',  headers: {    'x-not-found': 'true',  },})\n```\n\nStub response with a fixture that is read as a Buffer:\n\n```\ncy.intercept('/not-found', {  fixture: 'media/gif.mp4,null',})\n```\n\nSee also [`StaticResponse` object](#StaticResponse-objects).\n",
      "section": "api",
      "anchors": [
        "with-a-staticresponse-object"
      ],
      "path": "/llm/json/chunked/api/commands/intercept.json",
      "token_estimate": 133
    },
    {
      "id": "api/commands/intercept#using-the-routehandler-function",
      "doc_id": "api/commands/intercept",
      "heading": "Using the routeHandler function",
      "heading_level": 3,
      "content_markdown": "### Using the **`routeHandler`** function\n\nBy specifying a [`routeHandler`](#routeHandler-Function) function as the last argument to `cy.intercept`, you'll have access to the entire request-response session, enabling you to modify the outgoing request, manipulate the real response, make assertions, etc.\n\nThe `routeHandler` takes the incoming HTTP request (`IncomingHTTPRequest`) as the first argument.\n\n```\ncy.intercept('/users*', (req) => {  /* do something with request and/or response */})\n```\n\nThroughout these examples we will refer to the incoming HTTP request as `req`. Those of you with [Express.js](https://expressjs.com/) [middleware](https://expressjs.com/en/guide/writing-middleware.html) experience should be familiar with this syntax.\n\n#### Asserting on a request\n\n```\ncy.intercept('POST', '/organization', (req) => {  expect(req.body).to.include('Acme Company')})\n```\n\n#### Modifying an outgoing request\n\nYou can use the request handler callback to modify the [intercepted request object](#Intercepted-requests) before it is sent.\n\n```\n// set the request body to something different// before it's sent to the destinationcy.intercept('POST', '/login', (req) => {  req.body = 'username=janelane&password=secret123'})// dynamically set the aliascy.intercept('POST', '/login', (req) => {  req.alias = 'login'})\n```\n\n#### Adding a header to an outgoing request\n\nYou can add a header to an outgoing request, or modify an existing header\n\n```\ncy.intercept('/req-headers', (req) => {  req.headers['x-custom-headers'] = 'added by cy.intercept'})\n```\n\n**Note:** the new header will NOT be shown in the browser's Network tab, as the request has already left the browser. You can still confirm the header was added by waiting on the intercept as shown below:\n\n#### Waiting on the intercept\n\n```\ncy.intercept('/req-headers', (req) => {  req.headers['x-custom-headers'] = 'added by cy.intercept'}).as('headers')// the application makes the call ...// confirm the custom header was addedcy.wait('@headers')  .its('request.headers')  .should('have.property', 'x-custom-headers', 'added by cy.intercept')\n```\n\n#### Add, modify or delete a header to all outgoing requests\n\nYou can add, modify or delete a header to all outgoing requests using a `beforeEach()` in the [supportFile](/llm/markdown/app/core-concepts/writing-and-organizing-tests.md#Support-file).\n\n```\nbeforeEach(() => {  cy.intercept(    { url: 'http://localhost:3001/**', middleware: true },    // Delete 'if-none-match' header from all outgoing requests    (req) => delete req.headers['if-none-match']  )})\n```\n\n#### Dynamically stubbing a response\n\nYou can use the [`req.reply()`](#Providing-a-stub-response-with-reqreply) function to dynamically control the response to a request.\n\n```\ncy.intercept('/billing', (req) => {  // functions on 'req' can be used to  // dynamically respond to a request here  // send the request to the destination server  req.reply()  // respond to the request with a JSON object  req.reply({ plan: 'starter' })  // send the request to the destination server  // and intercept the response  req.continue((res) => {    // 'res' represents the real destination's response    // See \"Intercepting a response\" for more details and examples  })})\n```\n\nSee [\"Intercepted requests\"](#Intercepted-requests) for more information on the `req` object and its properties and methods.\n\n#### Returning a Promise\n\nIf a Promise is returned from the route callback, it will be awaited before continuing with the request.\n\n```\ncy.intercept('POST', '/login', (req) => {  // you could asynchronously fetch test data...  return getLoginCredentials().then((credentials) => {    // ...and then, use it to supplement the outgoing request    req.headers['authorization'] = credentials  })})\n```\n\n#### Passing a request to the next request handler\n\nIf [`req.reply()`](#Providing-a-stub-response-with-reqreply) or [`req.continue()`](#Controlling-the-outbound-request-with-reqcontinue) is not explicitly called inside of a request handler, requests will pass to the next request handler until none are left.\n\n```\n// you could have a top-level middleware handler that// sets an auth token on all requests// but remember setting `middleware: true` will// cause this to always be called firstcy.intercept('http://api.company.com/', { middleware: true }, (req) => {  req.headers['authorization'] = `token ${token}`})// and then have another handler that// more narrowly asserts on certain requestscy.intercept('POST', 'http://api.company.com/widgets', (req) => {  expect(req.body).to.include('analytics')})// a POST request to http://api.company.com/widgets would hit both// of those callbacks, middleware first, then the request would be// sent out with the modified request headers to the// real destination\n```\n",
      "section": "api",
      "anchors": [
        "using-the-routehandler-function"
      ],
      "path": "/llm/json/chunked/api/commands/intercept.json",
      "token_estimate": 807
    },
    {
      "id": "api/commands/intercept#modifying-an-outgoing-request",
      "doc_id": "api/commands/intercept",
      "heading": "Modifying an outgoing request",
      "heading_level": 4,
      "content_markdown": "#### Modifying an outgoing request\n\nYou can use the request handler callback to modify the [intercepted request object](#Intercepted-requests) before it is sent.\n\n```\n// set the request body to something different// before it's sent to the destinationcy.intercept('POST', '/login', (req) => {  req.body = 'username=janelane&password=secret123'})// dynamically set the aliascy.intercept('POST', '/login', (req) => {  req.alias = 'login'})\n```\n",
      "section": "api",
      "anchors": [
        "modifying-an-outgoing-request"
      ],
      "path": "/llm/json/chunked/api/commands/intercept.json",
      "token_estimate": 75
    },
    {
      "id": "api/commands/intercept#adding-a-header-to-an-outgoing-request",
      "doc_id": "api/commands/intercept",
      "heading": "Adding a header to an outgoing request",
      "heading_level": 4,
      "content_markdown": "#### Adding a header to an outgoing request\n\nYou can add a header to an outgoing request, or modify an existing header\n\n```\ncy.intercept('/req-headers', (req) => {  req.headers['x-custom-headers'] = 'added by cy.intercept'})\n```\n\n**Note:** the new header will NOT be shown in the browser's Network tab, as the request has already left the browser. You can still confirm the header was added by waiting on the intercept as shown below:\n",
      "section": "api",
      "anchors": [
        "adding-a-header-to-an-outgoing-request"
      ],
      "path": "/llm/json/chunked/api/commands/intercept.json",
      "token_estimate": 93
    },
    {
      "id": "api/commands/intercept#waiting-on-the-intercept",
      "doc_id": "api/commands/intercept",
      "heading": "Waiting on the intercept",
      "heading_level": 4,
      "content_markdown": "#### Waiting on the intercept\n\n```\ncy.intercept('/req-headers', (req) => {  req.headers['x-custom-headers'] = 'added by cy.intercept'}).as('headers')// the application makes the call ...// confirm the custom header was addedcy.wait('@headers')  .its('request.headers')  .should('have.property', 'x-custom-headers', 'added by cy.intercept')\n```\n",
      "section": "api",
      "anchors": [
        "waiting-on-the-intercept"
      ],
      "path": "/llm/json/chunked/api/commands/intercept.json",
      "token_estimate": 45
    },
    {
      "id": "api/commands/intercept#add-modify-or-delete-a-header-to-all-outgoing-requests",
      "doc_id": "api/commands/intercept",
      "heading": "Add, modify or delete a header to all outgoing requests",
      "heading_level": 4,
      "content_markdown": "#### Add, modify or delete a header to all outgoing requests\n\nYou can add, modify or delete a header to all outgoing requests using a `beforeEach()` in the [supportFile](/llm/markdown/app/core-concepts/writing-and-organizing-tests.md#Support-file).\n\n```\nbeforeEach(() => {  cy.intercept(    { url: 'http://localhost:3001/**', middleware: true },    // Delete 'if-none-match' header from all outgoing requests    (req) => delete req.headers['if-none-match']  )})\n```\n",
      "section": "api",
      "anchors": [
        "add-modify-or-delete-a-header-to-all-outgoing-requests"
      ],
      "path": "/llm/json/chunked/api/commands/intercept.json",
      "token_estimate": 72
    },
    {
      "id": "api/commands/intercept#dynamically-stubbing-a-response",
      "doc_id": "api/commands/intercept",
      "heading": "Dynamically stubbing a response",
      "heading_level": 4,
      "content_markdown": "#### Dynamically stubbing a response\n\nYou can use the [`req.reply()`](#Providing-a-stub-response-with-reqreply) function to dynamically control the response to a request.\n\n```\ncy.intercept('/billing', (req) => {  // functions on 'req' can be used to  // dynamically respond to a request here  // send the request to the destination server  req.reply()  // respond to the request with a JSON object  req.reply({ plan: 'starter' })  // send the request to the destination server  // and intercept the response  req.continue((res) => {    // 'res' represents the real destination's response    // See \"Intercepting a response\" for more details and examples  })})\n```\n\nSee [\"Intercepted requests\"](#Intercepted-requests) for more information on the `req` object and its properties and methods.\n",
      "section": "api",
      "anchors": [
        "dynamically-stubbing-a-response"
      ],
      "path": "/llm/json/chunked/api/commands/intercept.json",
      "token_estimate": 148
    },
    {
      "id": "api/commands/intercept#returning-a-promise",
      "doc_id": "api/commands/intercept",
      "heading": "Returning a Promise",
      "heading_level": 4,
      "content_markdown": "#### Returning a Promise\n\nIf a Promise is returned from the route callback, it will be awaited before continuing with the request.\n\n```\ncy.intercept('POST', '/login', (req) => {  // you could asynchronously fetch test data...  return getLoginCredentials().then((credentials) => {    // ...and then, use it to supplement the outgoing request    req.headers['authorization'] = credentials  })})\n```\n",
      "section": "api",
      "anchors": [
        "returning-a-promise"
      ],
      "path": "/llm/json/chunked/api/commands/intercept.json",
      "token_estimate": 72
    },
    {
      "id": "api/commands/intercept#passing-a-request-to-the-next-request-handler",
      "doc_id": "api/commands/intercept",
      "heading": "Passing a request to the next request handler",
      "heading_level": 4,
      "content_markdown": "#### Passing a request to the next request handler\n\nIf [`req.reply()`](#Providing-a-stub-response-with-reqreply) or [`req.continue()`](#Controlling-the-outbound-request-with-reqcontinue) is not explicitly called inside of a request handler, requests will pass to the next request handler until none are left.\n\n```\n// you could have a top-level middleware handler that// sets an auth token on all requests// but remember setting `middleware: true` will// cause this to always be called firstcy.intercept('http://api.company.com/', { middleware: true }, (req) => {  req.headers['authorization'] = `token ${token}`})// and then have another handler that// more narrowly asserts on certain requestscy.intercept('POST', 'http://api.company.com/widgets', (req) => {  expect(req.body).to.include('analytics')})// a POST request to http://api.company.com/widgets would hit both// of those callbacks, middleware first, then the request would be// sent out with the modified request headers to the// real destination\n```\n",
      "section": "api",
      "anchors": [
        "passing-a-request-to-the-next-request-handler"
      ],
      "path": "/llm/json/chunked/api/commands/intercept.json",
      "token_estimate": 163
    },
    {
      "id": "api/commands/intercept#disabling-logs-for-a-request",
      "doc_id": "api/commands/intercept",
      "heading": "Disabling logs for a request",
      "heading_level": 3,
      "content_markdown": "### Disabling logs for a request\n\nBy default, Cypress logs all requests that match any `cy.intercept()`, as well as all `XMLHttpRequest`s and `fetch` requests. You can use `cy.intercept()` to disable these logs by passing `{ log: false }` in the second parameter:\n\n```\n// disable Cypress's default behavior of logging all XMLHttpRequests and fetchescy.intercept({ resourceType: /xhr|fetch/ }, { log: false })\n```\n\nNote: Currently, you can only enable/disable a request's logs when defining the `cy.intercept()`, not inside of an `intercept` callback. See [#26069](https://github.com/cypress-io/cypress/issues/26069).\n",
      "section": "api",
      "anchors": [
        "disabling-logs-for-a-request"
      ],
      "path": "/llm/json/chunked/api/commands/intercept.json",
      "token_estimate": 111
    },
    {
      "id": "api/commands/intercept#intercepting-a-response",
      "doc_id": "api/commands/intercept",
      "heading": "Intercepting a response",
      "heading_level": 3,
      "content_markdown": "### Intercepting a response\n\nInside of a callback passed to `req.continue()`, you can access the destination server's real response.\n\n```\ncy.intercept('/integrations', (req) => {  // req.continue() with a callback will send the request to  // the destination server  req.continue((res) => {    // 'res' represents the real destination response    // you can manipulate 'res' before it's sent to the browser  })})\n```\n\nSee [\"Intercepted responses\"](#Intercepted-responses) for more information on the `res` object. See [\"Controlling the outbound request with `req.continue()`\"](#Controlling-the-outbound-request-with-reqcontinue) for more information about `req.continue()`.\n\n#### Asserting on a response\n\n```\ncy.intercept('/projects/2', (req) => {  req.continue((res) => {    expect(res.body).to.include('My Project')  })})\n```\n\n#### Returning a Promise\n\nIf a Promise is returned from the route callback, it will be awaited before sending the response to the browser.\n\n```\ncy.intercept('/users', (req) => {  req.continue((res) => {    // the response will not be sent to the browser until    // 'waitForSomething()' resolves    return waitForSomething()  })})\n```\n\n#### Throttle or delay response all incoming responses\n\nYou can throttle or delay all incoming responses using a `beforeEach()` in the [supportFile](/llm/markdown/app/core-concepts/writing-and-organizing-tests.md#Support-file).\n\n```\n// Throttle API responses to simulate real-world conditionsbeforeEach(() => {  cy.intercept(    {      url: 'http://localhost:3001/**',      middleware: true,    },    (req) => {      req.on('response', (res) => {        // Throttle the response to 1 Mbps to simulate a        // mobile 3G connection        res.setThrottle(1000)      })    }  )})\n```\n",
      "section": "api",
      "anchors": [
        "intercepting-a-response"
      ],
      "path": "/llm/json/chunked/api/commands/intercept.json",
      "token_estimate": 288
    },
    {
      "id": "api/commands/intercept#returning-a-promise",
      "doc_id": "api/commands/intercept",
      "heading": "Returning a Promise",
      "heading_level": 4,
      "content_markdown": "#### Returning a Promise\n\nIf a Promise is returned from the route callback, it will be awaited before sending the response to the browser.\n\n```\ncy.intercept('/users', (req) => {  req.continue((res) => {    // the response will not be sent to the browser until    // 'waitForSomething()' resolves    return waitForSomething()  })})\n```\n",
      "section": "api",
      "anchors": [
        "returning-a-promise"
      ],
      "path": "/llm/json/chunked/api/commands/intercept.json",
      "token_estimate": 67
    },
    {
      "id": "api/commands/intercept#throttle-or-delay-response-all-incoming-responses",
      "doc_id": "api/commands/intercept",
      "heading": "Throttle or delay response all incoming responses",
      "heading_level": 4,
      "content_markdown": "#### Throttle or delay response all incoming responses\n\nYou can throttle or delay all incoming responses using a `beforeEach()` in the [supportFile](/llm/markdown/app/core-concepts/writing-and-organizing-tests.md#Support-file).\n\n```\n// Throttle API responses to simulate real-world conditionsbeforeEach(() => {  cy.intercept(    {      url: 'http://localhost:3001/**',      middleware: true,    },    (req) => {      req.on('response', (res) => {        // Throttle the response to 1 Mbps to simulate a        // mobile 3G connection        res.setThrottle(1000)      })    }  )})\n```\n",
      "section": "api",
      "anchors": [
        "throttle-or-delay-response-all-incoming-responses"
      ],
      "path": "/llm/json/chunked/api/commands/intercept.json",
      "token_estimate": 88
    },
    {
      "id": "api/commands/intercept#request-response-modification-with-routehandler",
      "doc_id": "api/commands/intercept",
      "heading": "Request/Response Modification with routeHandler",
      "heading_level": 3,
      "content_markdown": "### Request/Response Modification with `routeHandler`\n\nSpecify [`routeHandler`](#routeHandler-Function) as the last argument to modify the outgoing request, stub a response, make assertions, etc.\n\nIf a function is passed as the `routeHandler`, it will be called with the intercepted HTTP request:\n\n```\ncy.intercept('/api', (req) => {  // do something with the intercepted request})\n```\n\nFrom here, you can do several things with the intercepted request:\n\n*   modify and make assertions on the request like its body, headers, URL, method, etc. ([example](#Asserting-on-a-request-1))\n*   stub out the response without interacting with a real back-end ([example](#Controlling-the-response)\n*   pass the request through to its destination and modify or make assertions on the real response on its way back ([example](#Controlling-the-response))\n*   attach listeners to various events on the request ([example](#Controlling-the-response))\n\n#### Asserting on a request\n\nYou can use the request handler callback to make an assertion on the [intercepted request object](#Intercepted-requests) before it is sent.\n\n```\n// match requests to create a usercy.intercept('POST', '/users', (req) => {  // make an assertion on the payload contents  expect(req.body).to.include('Peter Pan')})\n```\n\n#### Controlling the outgoing request\n\nThe outgoing request, including its body, headers, etc., can be modified before it's sent.\n\n```\n// modify the request body before it's sent to its destinationcy.intercept('POST', '/users', (req) => {  req.body = {    name: 'Peter Pan',  }})// add a header to an outgoing requestcy.intercept('POST', '/users', (req) => {  req.headers['x-custom-header'] = 'added by cy.intercept'})// modify an existing headercy.intercept('POST', '/users', (req) => {  req.headers['authorization'] = 'Basic YWxhZGRpbjpvcGVuc2VzYW1l'})\n```\n\n#### Verifying the request modification\n\n```\ncy.intercept('POST', '/users', (req) => {  req.headers['x-custom-header'] = 'added by cy.intercept'}).as('createUser')cy.get('button.save').click()// you can see the headers in the console output by selecting// this line in the command log:cy.wait('@createUser')  // ...or make an assertion:  .its('request.headers')  .should('have.property', 'x-custom-header', 'added by cy.intercept')\n```\n\nThe request modification cannot be verified by inspecting the browser's network traffic (for example, in Chrome DevTools), since the browser logs network traffic _before_ Cypress can intercept it.\n\n`cy.intercept()` cannot be debugged using [`cy.request()`](/llm/markdown/api/commands/request.md)! Cypress only intercepts requests made by your front-end application.\n\n#### Controlling the response\n\nThe intercepted request passed to the route handler (hereafter referred to as `req`, though you can use any name) contains methods to dynamically control the response to a request:\n\n*   `req.reply()` - stub out a response requiring no dependency on a real back-end\n*   `req.continue()` - modify or make assertions on the real response\n*   `req.destroy()` - destroy the request and respond with a network error\n*   `req.redirect()` - respond to the request with a redirect to a specified location\n*   `req.on()` - modify the response by attaching to events\n\nStubbing out a response (`req.reply()`):\n\n`req.reply()` takes a [`StaticResponse`](#StaticResponse-objects) object as the first argument:\n\n```\n// stub out the response without interacting with a real back-endcy.intercept('POST', '/users', (req) => {  req.reply({    headers: {      Set-Cookie: 'newUserName=Peter Pan;'    },    statusCode: 201,    body: {      name: 'Peter Pan'    },    delay: 10, // milliseconds    throttleKbps: 1000, // to simulate a 3G connection    forceNetworkError: false // default  })})// stub out a response body using a fixturecy.intercept('GET', '/users', (req) => {  req.reply({    statusCode: 200, // default    fixture: 'users.json'  })})\n```\n\nSee [`StaticResponse` objects](#StaticResponse-objects) below for more information.\n\nThe `reply` method also supports shorthand to avoid having to specify a `StaticResponse` object:\n\n```\n// equivalent to `req.reply({ body })`req.reply(body)// equivalent to `req.reply({ body, headers })`req.reply(body, headers)// equivalent to `req.reply({ statusCode, body, headers})`req.reply(statusCode, body, headers)\n```\n\nNote: Calling `reply()` will end the request phase and stop the request from propagating to the next matching request handler in line. See [Interception Lifecycle](#Interception-lifecycle).\n\nSee also [Providing a stub response with `req.reply()`](#Providing-a-stub-response-with-reqreply)\n\nModifying the real response (`continue`):\n\nThe `continue` method accepts a function which is passed an object representing the real response being intercepted on its way back to the client (your front-end application).\n\n```\n// pass the request through and make an assertion on// the real responsecy.intercept('POST', '/users', (req) => {  req.continue((res) => {    expect(res.body).to.include('Peter Pan')  })})\n```\n\nSee also [Controlling the outbound request with `req.continue()`](#Controlling-the-outbound-request-with-reqcontinue)\n\nResponding with a network error (`destroy`):\n\n```\n// dynamically destroy the request and// respond with a network errorcy.intercept('POST', '/users', (req) => {  if (mustDestroy(req)) {    req.destroy()  }  function mustDestroy(req) {    // code that determines whether to force a network error    // based on the contents of `req`  }})\n```\n\nResponding with a new location (`redirect`):\n\n```\n// respond to this request with a redirect to a new 'location'cy.intercept('GET', '/users', (req) => {  // statusCode defaults to `302`  req.redirect('/customers', 301)})\n```\n\nResponding by listening to events (`on`):\n\n```\ncy.intercept('GET', '/users', (req) => {  req.on('before:response', (res) => {    // do something when the `before:response` event is triggered  })})cy.intercept('POST', '/users', (req) => {  req.on('response', (res) => {    // do something when the `response` event is triggered  })})\n```\n\nSee example for [throttling a response](#Throttle-or-delay-response-all-incoming-responses) See more examples of [events](#Request-events)\n\n#### Returning a Promise\n\nIf a Promise is returned from the route callback, it will be awaited before continuing with the request.\n\n```\ncy.intercept('POST', '/users', (req) => {  // asynchronously fetch test data  return getAuthToken().then((token) => {    // ...and apply it to the outgoing request    req.headers['Authorization'] = `Basic ${token}`  })})cy.intercept('POST', '/users', (req) => {  req.continue((res) => {    // the response will not be sent to the browser until    // `waitForSomething()` resolves:    return waitForSomething()  })})\n```\n\n#### Stubbing a response with a string\n\n```\n// requests to create a user will be fulfilled// with a body of 'success'cy.intercept('POST', '/users', 'success')// { body: 'success' }\n```\n",
      "section": "api",
      "anchors": [
        "request-response-modification-with-routehandler"
      ],
      "path": "/llm/json/chunked/api/commands/intercept.json",
      "token_estimate": 1185
    },
    {
      "id": "api/commands/intercept#asserting-on-a-request",
      "doc_id": "api/commands/intercept",
      "heading": "Asserting on a request",
      "heading_level": 4,
      "content_markdown": "#### Asserting on a request\n\nYou can use the request handler callback to make an assertion on the [intercepted request object](#Intercepted-requests) before it is sent.\n\n```\n// match requests to create a usercy.intercept('POST', '/users', (req) => {  // make an assertion on the payload contents  expect(req.body).to.include('Peter Pan')})\n```\n",
      "section": "api",
      "anchors": [
        "asserting-on-a-request"
      ],
      "path": "/llm/json/chunked/api/commands/intercept.json",
      "token_estimate": 64
    },
    {
      "id": "api/commands/intercept#controlling-the-outgoing-request",
      "doc_id": "api/commands/intercept",
      "heading": "Controlling the outgoing request",
      "heading_level": 4,
      "content_markdown": "#### Controlling the outgoing request\n\nThe outgoing request, including its body, headers, etc., can be modified before it's sent.\n\n```\n// modify the request body before it's sent to its destinationcy.intercept('POST', '/users', (req) => {  req.body = {    name: 'Peter Pan',  }})// add a header to an outgoing requestcy.intercept('POST', '/users', (req) => {  req.headers['x-custom-header'] = 'added by cy.intercept'})// modify an existing headercy.intercept('POST', '/users', (req) => {  req.headers['authorization'] = 'Basic YWxhZGRpbjpvcGVuc2VzYW1l'})\n```\n",
      "section": "api",
      "anchors": [
        "controlling-the-outgoing-request"
      ],
      "path": "/llm/json/chunked/api/commands/intercept.json",
      "token_estimate": 95
    },
    {
      "id": "api/commands/intercept#verifying-the-request-modification",
      "doc_id": "api/commands/intercept",
      "heading": "Verifying the request modification",
      "heading_level": 4,
      "content_markdown": "#### Verifying the request modification\n\n```\ncy.intercept('POST', '/users', (req) => {  req.headers['x-custom-header'] = 'added by cy.intercept'}).as('createUser')cy.get('button.save').click()// you can see the headers in the console output by selecting// this line in the command log:cy.wait('@createUser')  // ...or make an assertion:  .its('request.headers')  .should('have.property', 'x-custom-header', 'added by cy.intercept')\n```\n\nThe request modification cannot be verified by inspecting the browser's network traffic (for example, in Chrome DevTools), since the browser logs network traffic _before_ Cypress can intercept it.\n\n`cy.intercept()` cannot be debugged using [`cy.request()`](/llm/markdown/api/commands/request.md)! Cypress only intercepts requests made by your front-end application.\n",
      "section": "api",
      "anchors": [
        "verifying-the-request-modification"
      ],
      "path": "/llm/json/chunked/api/commands/intercept.json",
      "token_estimate": 117
    },
    {
      "id": "api/commands/intercept#controlling-the-response",
      "doc_id": "api/commands/intercept",
      "heading": "Controlling the response",
      "heading_level": 4,
      "content_markdown": "#### Controlling the response\n\nThe intercepted request passed to the route handler (hereafter referred to as `req`, though you can use any name) contains methods to dynamically control the response to a request:\n\n*   `req.reply()` - stub out a response requiring no dependency on a real back-end\n*   `req.continue()` - modify or make assertions on the real response\n*   `req.destroy()` - destroy the request and respond with a network error\n*   `req.redirect()` - respond to the request with a redirect to a specified location\n*   `req.on()` - modify the response by attaching to events\n\nStubbing out a response (`req.reply()`):\n\n`req.reply()` takes a [`StaticResponse`](#StaticResponse-objects) object as the first argument:\n\n```\n// stub out the response without interacting with a real back-endcy.intercept('POST', '/users', (req) => {  req.reply({    headers: {      Set-Cookie: 'newUserName=Peter Pan;'    },    statusCode: 201,    body: {      name: 'Peter Pan'    },    delay: 10, // milliseconds    throttleKbps: 1000, // to simulate a 3G connection    forceNetworkError: false // default  })})// stub out a response body using a fixturecy.intercept('GET', '/users', (req) => {  req.reply({    statusCode: 200, // default    fixture: 'users.json'  })})\n```\n\nSee [`StaticResponse` objects](#StaticResponse-objects) below for more information.\n\nThe `reply` method also supports shorthand to avoid having to specify a `StaticResponse` object:\n\n```\n// equivalent to `req.reply({ body })`req.reply(body)// equivalent to `req.reply({ body, headers })`req.reply(body, headers)// equivalent to `req.reply({ statusCode, body, headers})`req.reply(statusCode, body, headers)\n```\n\nNote: Calling `reply()` will end the request phase and stop the request from propagating to the next matching request handler in line. See [Interception Lifecycle](#Interception-lifecycle).\n\nSee also [Providing a stub response with `req.reply()`](#Providing-a-stub-response-with-reqreply)\n\nModifying the real response (`continue`):\n\nThe `continue` method accepts a function which is passed an object representing the real response being intercepted on its way back to the client (your front-end application).\n\n```\n// pass the request through and make an assertion on// the real responsecy.intercept('POST', '/users', (req) => {  req.continue((res) => {    expect(res.body).to.include('Peter Pan')  })})\n```\n\nSee also [Controlling the outbound request with `req.continue()`](#Controlling-the-outbound-request-with-reqcontinue)\n\nResponding with a network error (`destroy`):\n\n```\n// dynamically destroy the request and// respond with a network errorcy.intercept('POST', '/users', (req) => {  if (mustDestroy(req)) {    req.destroy()  }  function mustDestroy(req) {    // code that determines whether to force a network error    // based on the contents of `req`  }})\n```\n\nResponding with a new location (`redirect`):\n\n```\n// respond to this request with a redirect to a new 'location'cy.intercept('GET', '/users', (req) => {  // statusCode defaults to `302`  req.redirect('/customers', 301)})\n```\n\nResponding by listening to events (`on`):\n\n```\ncy.intercept('GET', '/users', (req) => {  req.on('before:response', (res) => {    // do something when the `before:response` event is triggered  })})cy.intercept('POST', '/users', (req) => {  req.on('response', (res) => {    // do something when the `response` event is triggered  })})\n```\n\nSee example for [throttling a response](#Throttle-or-delay-response-all-incoming-responses) See more examples of [events](#Request-events)\n",
      "section": "api",
      "anchors": [
        "controlling-the-response"
      ],
      "path": "/llm/json/chunked/api/commands/intercept.json",
      "token_estimate": 607
    },
    {
      "id": "api/commands/intercept#returning-a-promise",
      "doc_id": "api/commands/intercept",
      "heading": "Returning a Promise",
      "heading_level": 4,
      "content_markdown": "#### Returning a Promise\n\nIf a Promise is returned from the route callback, it will be awaited before continuing with the request.\n\n```\ncy.intercept('POST', '/users', (req) => {  // asynchronously fetch test data  return getAuthToken().then((token) => {    // ...and apply it to the outgoing request    req.headers['Authorization'] = `Basic ${token}`  })})cy.intercept('POST', '/users', (req) => {  req.continue((res) => {    // the response will not be sent to the browser until    // `waitForSomething()` resolves:    return waitForSomething()  })})\n```\n",
      "section": "api",
      "anchors": [
        "returning-a-promise"
      ],
      "path": "/llm/json/chunked/api/commands/intercept.json",
      "token_estimate": 100
    },
    {
      "id": "api/commands/intercept#intercepted-requests",
      "doc_id": "api/commands/intercept",
      "heading": "Intercepted requests",
      "heading_level": 2,
      "content_markdown": "## Intercepted requests\n\nIf a function is passed as the handler for a `cy.intercept()`, it will be called with the first argument being an object that represents the intercepted HTTP request:\n\n```\ncy.intercept('/api', (req) => {  // `req` represents the intercepted HTTP request})\n```\n\nFrom here, you can do several things with the intercepted request:\n\n*   you can modify and assert on the request's properties (body, headers, URL, method...)\n*   the request can be sent to the real upstream server\n    *   optionally, you can intercept the response from this\n*   a response can be provided to stub out the request\n*   listeners can be attached to various events on the request\n\n### Request object properties\n\nThe request object (`req`) has several properties from the HTTP request itself:\n\n```\n{  /**   * The body of the request.   * If a JSON Content-Type was used and the body was valid JSON,   * this will be an object.   * If the body was binary content, this will be a buffer.   */  body: string | object | any  /**   * The headers of the request.   */  headers: { [key: string]: string }  /**   * Request HTTP method (GET, POST, ...).   */  method: string  /**   * Request URL.   */  url: string  /**   * URL query string as object.   */  query: Record<string, string|number>  /**   * The HTTP version used in the request. Read only.   */  httpVersion: string  /**   * The resource type of the request. Read only.   */  resourceType: 'document' | 'fetch' | 'xhr' | 'websocket' | 'stylesheet'              | 'script' | 'image' | 'font' | 'cspviolationreport' | 'ping'              | 'manifest' | 'other'}\n```\n\n`req` also has some optional properties which can be set to control Cypress-specific behavior:\n\n```\n{  /**   * If provided, the number of milliseconds before an upstream   * response to this request will time out and cause an error.   * By default, `responseTimeout` from config is used.   */  responseTimeout?: number  /**   * Set if redirects should be followed when this request is made.   * By default, requests will not follow redirects before   * yielding the response (the 3xx redirect is yielded).   */  followRedirect?: boolean  /**   * If set, `cy.wait` can be used to await the request/response   * cycle to complete for this request via `cy.wait('@alias')`.   */  alias?: string}\n```\n\nAny modifications to the properties of `req` will be persisted to other request handlers, and finally merged into the actual outbound HTTP request.\n\n### Controlling the outbound request with `req.continue()`\n\nCalling `req.continue()` without any argument will cause the request to be sent outgoing, and the response will be returned to the browser after any other listeners have been called. For example, the following code modifies a `POST` request and then sends it to the upstream server:\n\n```\ncy.intercept('POST', '/submitStory', (req) => {  req.body.storyName = 'some name'  // send the modified request and skip any other  // matching request handlers  req.continue()})\n```\n\nIf a function is passed to `req.continue()`, the request will be sent to the real upstream server, and the callback will be called with the response once the response is fully received from the server. See [\"Intercepted responses\"](#Intercepted-responses)\n\nNote: calling `req.continue()` will stop the request from propagating to the next matching request handler in line. See [\"Interception lifecycle\"](#Interception-lifecycle) for more information.\n\n### Providing a stub response with `req.reply()`\n\nThe `req.reply()` function can be used to send a stub response for an intercepted request. By passing a string, object, or [`StaticResponse`](#StaticResponse-objects) to `req.reply()`, the request can be preventing from reaching the destination server.\n\nFor example, the following code stubs out a JSON response from a request interceptor:\n\n```\ncy.intercept('/billing', (req) => {  // dynamically get billing plan name at request-time  const planName = getPlanName()  // this object will automatically be JSON.stringified and  // sent as the response  req.reply({ plan: planName })})\n```\n\nInstead of passing a plain object or string to `req.reply()`, you can also pass a [`StaticResponse`](#StaticResponse-objects) object. With a [`StaticResponse`](#StaticResponse-objects), you can force a network error, delay/throttle the response, send a fixture, and more.\n\nFor example, the following code serves a dynamically chosen fixture with a delay of 500ms:\n\n```\ncy.intercept('/api/users/*', async (req) => {  // asynchronously retrieve fixture filename at request-time  const fixtureFilename = await getFixtureFilenameForUrl(req.url)  req.reply({    fixture: fixtureFilename,    delay: 500,  })})\n```\n\nSee the [`StaticResponse` documentation](#StaticResponse-objects) for more information on stubbing responses in this manner.\n\n#### `req.reply()` shorthand\n\n`req.reply()` also supports shorthand, similar to [`res.send()`](#Ending-the-response-with-ressend), to avoid having to specify a `StaticResponse` object:\n\n```\n// equivalent to `req.reply({ body })`req.reply(body)// equivalent to `req.reply({ body, headers })`req.reply(body, headers)// equivalent to `req.reply({ statusCode, body, headers})`req.reply(statusCode, body, headers)\n```\n\n#### Convenience functions\n\nThere are also two convenience functions available on `req`:\n\n```\n{  /**   * Destroy the request and respond with a network error.   */  destroy(): void  /**   * Respond to this request with a redirect to a new 'location'.   * @param statusCode HTTP status code to redirect with. Default: 302   */  redirect(location: string, statusCode?: number): void}\n```\n\nSee examples in the [Controlling the response](#Controlling-the-response) section\n\nNote: calling `req.reply()` will end the request phase and stop the request from propagating to the next matching request handler in line. See [\"Interception lifecycle\"](#Interception-lifecycle) for more information.\n\n### Request events\n\nFor advanced use, several events are available on `req`, that represent different stages of the [Interception lifecycle](#Interception-lifecycle).\n\nBy calling `req.on`, you can subscribe to different events:\n\n```\ncy.intercept('/shop', (req) => {  req.on('before:response', (res) => {    /**     * Emitted before `response` and before any `req.continue`     * handlers. Modifications to `res` will be applied to the     * incoming response. If a promise is returned, it will be     * awaited before processing other event handlers.     */  })  req.on('response', (res) => {    /**     * Emitted after `before:response` and after any     * `req.continue` handlers - before the response is sent     * to the browser. Modifications to `res` will be applied     * to the incoming response. If a promise is returned, it     * will be awaited before processing other event handlers.     */  })  req.on('after:response', (res) => {    /**     * Emitted once the response to a request has finished     * sending to the browser. Modifications to `res` have no     * impact. If a promise is returned, it will be awaited     * before processing other event handlers.     */  })})\n```\n\nSee [\"Intercepted responses\"](#Intercepted-responses) for more details on the `res` object yielded by `before:response` and `response`. See [\"Interception lifecycle\"](#Interception-lifecycle) for more details on request ordering.\n",
      "section": "api",
      "anchors": [
        "intercepted-requests"
      ],
      "path": "/llm/json/chunked/api/commands/intercept.json",
      "token_estimate": 1400
    },
    {
      "id": "api/commands/intercept#request-object-properties",
      "doc_id": "api/commands/intercept",
      "heading": "Request object properties",
      "heading_level": 3,
      "content_markdown": "### Request object properties\n\nThe request object (`req`) has several properties from the HTTP request itself:\n\n```\n{  /**   * The body of the request.   * If a JSON Content-Type was used and the body was valid JSON,   * this will be an object.   * If the body was binary content, this will be a buffer.   */  body: string | object | any  /**   * The headers of the request.   */  headers: { [key: string]: string }  /**   * Request HTTP method (GET, POST, ...).   */  method: string  /**   * Request URL.   */  url: string  /**   * URL query string as object.   */  query: Record<string, string|number>  /**   * The HTTP version used in the request. Read only.   */  httpVersion: string  /**   * The resource type of the request. Read only.   */  resourceType: 'document' | 'fetch' | 'xhr' | 'websocket' | 'stylesheet'              | 'script' | 'image' | 'font' | 'cspviolationreport' | 'ping'              | 'manifest' | 'other'}\n```\n\n`req` also has some optional properties which can be set to control Cypress-specific behavior:\n\n```\n{  /**   * If provided, the number of milliseconds before an upstream   * response to this request will time out and cause an error.   * By default, `responseTimeout` from config is used.   */  responseTimeout?: number  /**   * Set if redirects should be followed when this request is made.   * By default, requests will not follow redirects before   * yielding the response (the 3xx redirect is yielded).   */  followRedirect?: boolean  /**   * If set, `cy.wait` can be used to await the request/response   * cycle to complete for this request via `cy.wait('@alias')`.   */  alias?: string}\n```\n\nAny modifications to the properties of `req` will be persisted to other request handlers, and finally merged into the actual outbound HTTP request.\n",
      "section": "api",
      "anchors": [
        "request-object-properties"
      ],
      "path": "/llm/json/chunked/api/commands/intercept.json",
      "token_estimate": 384
    },
    {
      "id": "api/commands/intercept#controlling-the-outbound-request-with-req-continue",
      "doc_id": "api/commands/intercept",
      "heading": "Controlling the outbound request with req.continue()",
      "heading_level": 3,
      "content_markdown": "### Controlling the outbound request with `req.continue()`\n\nCalling `req.continue()` without any argument will cause the request to be sent outgoing, and the response will be returned to the browser after any other listeners have been called. For example, the following code modifies a `POST` request and then sends it to the upstream server:\n\n```\ncy.intercept('POST', '/submitStory', (req) => {  req.body.storyName = 'some name'  // send the modified request and skip any other  // matching request handlers  req.continue()})\n```\n\nIf a function is passed to `req.continue()`, the request will be sent to the real upstream server, and the callback will be called with the response once the response is fully received from the server. See [\"Intercepted responses\"](#Intercepted-responses)\n\nNote: calling `req.continue()` will stop the request from propagating to the next matching request handler in line. See [\"Interception lifecycle\"](#Interception-lifecycle) for more information.\n",
      "section": "api",
      "anchors": [
        "controlling-the-outbound-request-with-req-continue"
      ],
      "path": "/llm/json/chunked/api/commands/intercept.json",
      "token_estimate": 185
    },
    {
      "id": "api/commands/intercept#providing-a-stub-response-with-req-reply",
      "doc_id": "api/commands/intercept",
      "heading": "Providing a stub response with req.reply()",
      "heading_level": 3,
      "content_markdown": "### Providing a stub response with `req.reply()`\n\nThe `req.reply()` function can be used to send a stub response for an intercepted request. By passing a string, object, or [`StaticResponse`](#StaticResponse-objects) to `req.reply()`, the request can be preventing from reaching the destination server.\n\nFor example, the following code stubs out a JSON response from a request interceptor:\n\n```\ncy.intercept('/billing', (req) => {  // dynamically get billing plan name at request-time  const planName = getPlanName()  // this object will automatically be JSON.stringified and  // sent as the response  req.reply({ plan: planName })})\n```\n\nInstead of passing a plain object or string to `req.reply()`, you can also pass a [`StaticResponse`](#StaticResponse-objects) object. With a [`StaticResponse`](#StaticResponse-objects), you can force a network error, delay/throttle the response, send a fixture, and more.\n\nFor example, the following code serves a dynamically chosen fixture with a delay of 500ms:\n\n```\ncy.intercept('/api/users/*', async (req) => {  // asynchronously retrieve fixture filename at request-time  const fixtureFilename = await getFixtureFilenameForUrl(req.url)  req.reply({    fixture: fixtureFilename,    delay: 500,  })})\n```\n\nSee the [`StaticResponse` documentation](#StaticResponse-objects) for more information on stubbing responses in this manner.\n\n#### `req.reply()` shorthand\n\n`req.reply()` also supports shorthand, similar to [`res.send()`](#Ending-the-response-with-ressend), to avoid having to specify a `StaticResponse` object:\n\n```\n// equivalent to `req.reply({ body })`req.reply(body)// equivalent to `req.reply({ body, headers })`req.reply(body, headers)// equivalent to `req.reply({ statusCode, body, headers})`req.reply(statusCode, body, headers)\n```\n\n#### Convenience functions\n\nThere are also two convenience functions available on `req`:\n\n```\n{  /**   * Destroy the request and respond with a network error.   */  destroy(): void  /**   * Respond to this request with a redirect to a new 'location'.   * @param statusCode HTTP status code to redirect with. Default: 302   */  redirect(location: string, statusCode?: number): void}\n```\n\nSee examples in the [Controlling the response](#Controlling-the-response) section\n\nNote: calling `req.reply()` will end the request phase and stop the request from propagating to the next matching request handler in line. See [\"Interception lifecycle\"](#Interception-lifecycle) for more information.\n",
      "section": "api",
      "anchors": [
        "providing-a-stub-response-with-req-reply"
      ],
      "path": "/llm/json/chunked/api/commands/intercept.json",
      "token_estimate": 417
    },
    {
      "id": "api/commands/intercept#req-reply-shorthand",
      "doc_id": "api/commands/intercept",
      "heading": "req.reply() shorthand",
      "heading_level": 4,
      "content_markdown": "#### `req.reply()` shorthand\n\n`req.reply()` also supports shorthand, similar to [`res.send()`](#Ending-the-response-with-ressend), to avoid having to specify a `StaticResponse` object:\n\n```\n// equivalent to `req.reply({ body })`req.reply(body)// equivalent to `req.reply({ body, headers })`req.reply(body, headers)// equivalent to `req.reply({ statusCode, body, headers})`req.reply(statusCode, body, headers)\n```\n",
      "section": "api",
      "anchors": [
        "req-reply-shorthand"
      ],
      "path": "/llm/json/chunked/api/commands/intercept.json",
      "token_estimate": 55
    },
    {
      "id": "api/commands/intercept#convenience-functions",
      "doc_id": "api/commands/intercept",
      "heading": "Convenience functions",
      "heading_level": 4,
      "content_markdown": "#### Convenience functions\n\nThere are also two convenience functions available on `req`:\n\n```\n{  /**   * Destroy the request and respond with a network error.   */  destroy(): void  /**   * Respond to this request with a redirect to a new 'location'.   * @param statusCode HTTP status code to redirect with. Default: 302   */  redirect(location: string, statusCode?: number): void}\n```\n\nSee examples in the [Controlling the response](#Controlling-the-response) section\n\nNote: calling `req.reply()` will end the request phase and stop the request from propagating to the next matching request handler in line. See [\"Interception lifecycle\"](#Interception-lifecycle) for more information.\n",
      "section": "api",
      "anchors": [
        "convenience-functions"
      ],
      "path": "/llm/json/chunked/api/commands/intercept.json",
      "token_estimate": 127
    },
    {
      "id": "api/commands/intercept#request-events",
      "doc_id": "api/commands/intercept",
      "heading": "Request events",
      "heading_level": 3,
      "content_markdown": "### Request events\n\nFor advanced use, several events are available on `req`, that represent different stages of the [Interception lifecycle](#Interception-lifecycle).\n\nBy calling `req.on`, you can subscribe to different events:\n\n```\ncy.intercept('/shop', (req) => {  req.on('before:response', (res) => {    /**     * Emitted before `response` and before any `req.continue`     * handlers. Modifications to `res` will be applied to the     * incoming response. If a promise is returned, it will be     * awaited before processing other event handlers.     */  })  req.on('response', (res) => {    /**     * Emitted after `before:response` and after any     * `req.continue` handlers - before the response is sent     * to the browser. Modifications to `res` will be applied     * to the incoming response. If a promise is returned, it     * will be awaited before processing other event handlers.     */  })  req.on('after:response', (res) => {    /**     * Emitted once the response to a request has finished     * sending to the browser. Modifications to `res` have no     * impact. If a promise is returned, it will be awaited     * before processing other event handlers.     */  })})\n```\n\nSee [\"Intercepted responses\"](#Intercepted-responses) for more details on the `res` object yielded by `before:response` and `response`. See [\"Interception lifecycle\"](#Interception-lifecycle) for more details on request ordering.\n",
      "section": "api",
      "anchors": [
        "request-events"
      ],
      "path": "/llm/json/chunked/api/commands/intercept.json",
      "token_estimate": 265
    },
    {
      "id": "api/commands/intercept#intercepted-responses",
      "doc_id": "api/commands/intercept",
      "heading": "Intercepted responses",
      "heading_level": 2,
      "content_markdown": "## Intercepted responses\n\nThe response can be intercepted in two ways:\n\n*   by passing a callback to [`req.continue()`](#Controlling-the-outbound-request-with-reqcontinue) within a request handler\n*   by listening for the `before:response` or `response` request events (see [\"Request events\"](#Request-events))\n\nThe response object, `res`, will be passed as the first argument to the handler function:\n\n```\ncy.intercept('/url', (req) => {  req.on('before:response', (res) => {    // this will be called before any `req.continue` or    // `response` handlers  })  req.continue((res) => {    // this will be called after all `before:response`    // handlers and before any `response` handlers    // by calling `req.continue`, we signal that this    // request handler will be the last one, and that    // the request should be sent outgoing at this point.    // for that reason, there can only be one    // `req.continue` handler per request.  })  req.on('response', (res) => {    // this will be called after all `before:response`    // handlers and after the `req.continue` handler    // but before the response is sent to the browser  })})\n```\n\n### Response object properties\n\nThe response object (`res`) yielded to response handlers has several properties from the HTTP response itself. All of the following properties on `res` can be modified:\n\n| Property | Description |\n| --- | --- |\n| body | response body (`object`, `string`, `ArrayBuffer`) |\n| headers | response headers (`object`) |\n| statusCode | response status code (`number`) |\n| statusMessage | response status message (`string`) |\n\n**Note about `body`:** If the response header contains `Content-Type: application/json` and the body contains valid JSON, this will be an `object`. And if the body contains binary content, this will be a buffer.\n\n`res` also has some optional properties which can be set to control Cypress-specific behavior:\n\n| Property | Description |\n| --- | --- |\n| throttleKbps | Maximum data transfer rate of the response (kilobits/second) |\n| delay | Minimum network latency or delay to add to the response time (milliseconds) |\n\nAny modifications to the properties of `res` will be persisted to other response handlers, and finally merged into the actual incoming HTTP response.\n\n### Ending the response with `res.send()`\n\nTo end the response phase of the request, call `res.send()`. Optionally, you can pass a [`StaticResponse`](#StaticResponse-objects) to `res.send()`, to be merged with the actual response.\n\nWhen `res.send()` is called, the response phase will end immediately and no other response handlers will be called for the current request. Here is an example of how `res.send()` could be used:\n\n```\ncy.intercept('/notification', (req) => {  req.continue((res) => {    if (res.body.status === 'failed') {      // sends a fixture body instead of the existing 'res.body'      res.send({ fixture: 'success.json' })    }  })})\n```\n\nSee the [`StaticResponse` documentation](#StaticResponse-objects) for more information on the format.\n\n#### `res.send()` shorthand\n\n`res.send()` also supports shorthand, similar to [`req.reply()`](#Providing-a-stub-response-with-reqreply), to avoid having to specify a `StaticResponse` object:\n\n```\n// equivalent to `res.send({ body })`res.send(body)// equivalent to `res.send({ body, headers })`res.send(body, headers)// equivalent to `res.send({ statusCode, body, headers})`res.send(statusCode, body, headers)\n```\n\n#### Convenience functions\n\nThere are also two convenience functions available on `res`:\n\n```\n{  /**   * Wait for 'delay' milliseconds before sending the   * response to the client.   */  setDelay: (delay: number) => IncomingHttpResponse  /**   * Serve the response at 'throttleKbps' kilobytes per second.   */  setThrottle: (throttleKbps: number) => IncomingHttpResponse}\n```\n\nNote: calling `res.send()` will end the response phase and stop the response from propagating to the next matching response handler in line. See [\"Interception lifecycle\"](#Interception-lifecycle) for more information.\n",
      "section": "api",
      "anchors": [
        "intercepted-responses"
      ],
      "path": "/llm/json/chunked/api/commands/intercept.json",
      "token_estimate": 756
    },
    {
      "id": "api/commands/intercept#response-object-properties",
      "doc_id": "api/commands/intercept",
      "heading": "Response object properties",
      "heading_level": 3,
      "content_markdown": "### Response object properties\n\nThe response object (`res`) yielded to response handlers has several properties from the HTTP response itself. All of the following properties on `res` can be modified:\n\n| Property | Description |\n| --- | --- |\n| body | response body (`object`, `string`, `ArrayBuffer`) |\n| headers | response headers (`object`) |\n| statusCode | response status code (`number`) |\n| statusMessage | response status message (`string`) |\n\n**Note about `body`:** If the response header contains `Content-Type: application/json` and the body contains valid JSON, this will be an `object`. And if the body contains binary content, this will be a buffer.\n\n`res` also has some optional properties which can be set to control Cypress-specific behavior:\n\n| Property | Description |\n| --- | --- |\n| throttleKbps | Maximum data transfer rate of the response (kilobits/second) |\n| delay | Minimum network latency or delay to add to the response time (milliseconds) |\n\nAny modifications to the properties of `res` will be persisted to other response handlers, and finally merged into the actual incoming HTTP response.\n",
      "section": "api",
      "anchors": [
        "response-object-properties"
      ],
      "path": "/llm/json/chunked/api/commands/intercept.json",
      "token_estimate": 240
    },
    {
      "id": "api/commands/intercept#ending-the-response-with-res-send",
      "doc_id": "api/commands/intercept",
      "heading": "Ending the response with res.send()",
      "heading_level": 3,
      "content_markdown": "### Ending the response with `res.send()`\n\nTo end the response phase of the request, call `res.send()`. Optionally, you can pass a [`StaticResponse`](#StaticResponse-objects) to `res.send()`, to be merged with the actual response.\n\nWhen `res.send()` is called, the response phase will end immediately and no other response handlers will be called for the current request. Here is an example of how `res.send()` could be used:\n\n```\ncy.intercept('/notification', (req) => {  req.continue((res) => {    if (res.body.status === 'failed') {      // sends a fixture body instead of the existing 'res.body'      res.send({ fixture: 'success.json' })    }  })})\n```\n\nSee the [`StaticResponse` documentation](#StaticResponse-objects) for more information on the format.\n\n#### `res.send()` shorthand\n\n`res.send()` also supports shorthand, similar to [`req.reply()`](#Providing-a-stub-response-with-reqreply), to avoid having to specify a `StaticResponse` object:\n\n```\n// equivalent to `res.send({ body })`res.send(body)// equivalent to `res.send({ body, headers })`res.send(body, headers)// equivalent to `res.send({ statusCode, body, headers})`res.send(statusCode, body, headers)\n```\n\n#### Convenience functions\n\nThere are also two convenience functions available on `res`:\n\n```\n{  /**   * Wait for 'delay' milliseconds before sending the   * response to the client.   */  setDelay: (delay: number) => IncomingHttpResponse  /**   * Serve the response at 'throttleKbps' kilobytes per second.   */  setThrottle: (throttleKbps: number) => IncomingHttpResponse}\n```\n\nNote: calling `res.send()` will end the response phase and stop the response from propagating to the next matching response handler in line. See [\"Interception lifecycle\"](#Interception-lifecycle) for more information.\n",
      "section": "api",
      "anchors": [
        "ending-the-response-with-res-send"
      ],
      "path": "/llm/json/chunked/api/commands/intercept.json",
      "token_estimate": 297
    },
    {
      "id": "api/commands/intercept#res-send-shorthand",
      "doc_id": "api/commands/intercept",
      "heading": "res.send() shorthand",
      "heading_level": 4,
      "content_markdown": "#### `res.send()` shorthand\n\n`res.send()` also supports shorthand, similar to [`req.reply()`](#Providing-a-stub-response-with-reqreply), to avoid having to specify a `StaticResponse` object:\n\n```\n// equivalent to `res.send({ body })`res.send(body)// equivalent to `res.send({ body, headers })`res.send(body, headers)// equivalent to `res.send({ statusCode, body, headers})`res.send(statusCode, body, headers)\n```\n",
      "section": "api",
      "anchors": [
        "res-send-shorthand"
      ],
      "path": "/llm/json/chunked/api/commands/intercept.json",
      "token_estimate": 55
    },
    {
      "id": "api/commands/intercept#convenience-functions",
      "doc_id": "api/commands/intercept",
      "heading": "Convenience functions",
      "heading_level": 4,
      "content_markdown": "#### Convenience functions\n\nThere are also two convenience functions available on `res`:\n\n```\n{  /**   * Wait for 'delay' milliseconds before sending the   * response to the client.   */  setDelay: (delay: number) => IncomingHttpResponse  /**   * Serve the response at 'throttleKbps' kilobytes per second.   */  setThrottle: (throttleKbps: number) => IncomingHttpResponse}\n```\n\nNote: calling `res.send()` will end the response phase and stop the response from propagating to the next matching response handler in line. See [\"Interception lifecycle\"](#Interception-lifecycle) for more information.\n",
      "section": "api",
      "anchors": [
        "convenience-functions"
      ],
      "path": "/llm/json/chunked/api/commands/intercept.json",
      "token_estimate": 105
    },
    {
      "id": "api/commands/intercept#staticresponse-objects",
      "doc_id": "api/commands/intercept",
      "heading": "StaticResponse objects",
      "heading_level": 2,
      "content_markdown": "## `StaticResponse` objects\n\nA `StaticResponse` represents a [statically defined response (stub)](#Stubbing-a-response).\n\nThe following properties are available on `StaticResponse`.\n\n| Option | Description |\n| --- | --- |\n| statusCode | HTTP response status code |\n| headers | HTTP response headers |\n| body | Serve a static response body (`object`, `string`, `ArrayBuffer`) (when `fixture` is omitted). |\n| fixture | Serve a fixture as the HTTP response body (allowed when `body` is omitted). Read the contents with an encoding other than the [default for the file type](/llm/markdown/api/commands/fixture.md#Encoding), pass the fixture like `path,encoding`. |\n| forceNetworkError | Force an error by destroying the browser connection |\n| delay | Minimum network latency or delay to add to the response time (milliseconds) |\n| throttleKbps | Maximum data transfer rate of the response (kilobits/second) |\n\n**Note:** All properties are optional.\n\nYou can supply a `StaticResponse` to Cypress in 3 ways:\n\n*   To `cy.intercept()` as [`an argument`](#staticResponse-StaticResponse), to stub a response to a route: `cy.intercept('/url', staticResponse)`\n*   To [`req.reply()`](#Providing-a-stub-response-with-reqreply), to stub a response from a request handler: `req.reply(staticResponse)`\n*   To [`res.send()`](#Ending-the-response-with-ressend), to stub a response from a response handler: `res.send(staticResponse)`\n\nSee [\"Stubbing a response with a `StaticResponse` object\"](#With-a-StaticResponse-object) for examples of stubbing with `cy.intercept()`.\n",
      "section": "api",
      "anchors": [
        "staticresponse-objects"
      ],
      "path": "/llm/json/chunked/api/commands/intercept.json",
      "token_estimate": 271
    },
    {
      "id": "api/commands/intercept#interception-lifecycle",
      "doc_id": "api/commands/intercept",
      "heading": "Interception lifecycle",
      "heading_level": 2,
      "content_markdown": "## Interception lifecycle\n\nThe lifecycle of a `cy.intercept()` interception begins when an HTTP request is sent from your app that matches one or more registered `cy.intercept()` routes. From there, each interception has two phases: request and response.\n\n`cy.intercept()` routes are matched in reverse order of definition, except for routes which are defined with `{ middleware: true }`, which always run first. This allows you to override existing `cy.intercept()` declarations by defining an overlapping `cy.intercept()`:\n\n### Request phase[​](#Request-phase)\n\nThe following steps are used to handle the request phase.\n\n1.  Start with the first matching route according to the above algorithm (middleware first, followed by handlers in reverse order).\n2.  Was a handler (body, [`StaticResponse`](#StaticResponse-objects), or function) supplied to `cy.intercept()`? If not, continue to step 7.\n3.  If the handler was a body or [`StaticResponse`](#StaticResponse-objects), immediately end the request with that response.\n4.  If the handler was a function, call the function with `req`, the incoming request, as the first argument. See [\"Intercepted requests\"](#Intercepted-requests) for more information on the `req` object.\n    *   If [`req.reply()`](#Providing-a-stub-response-with-reqreply) is called, immediately end the request phase with the provided response. See [\"Providing a stub response with `req.reply()`\"](#Providing-a-stub-response-with-reqreply).\n    *   If [`req.continue()`](#Controlling-the-outbound-request-with-reqcontinue) is called, immediately end the request phase, and send the request to the destination server. If a callback is provided to [`req.continue()`](#Controlling-the-outbound-request-with-reqcontinue), it will be called during the [response phase](#Response-phase)\n5.  If the handler returned a Promise, wait for the Promise to resolve.\n6.  Merge any modifications to the request object with the real request.\n7.  If there is another matching `cy.intercept()`, return to step 2 and continue following steps with that route.\n8.  Send the request outgoing to the destination server and end the request phase. The [response phase](#Response-phase) will begin once a response is received.\n\n### Response phase\n\nOnce the HTTP response is received from the upstream server, the following steps are applied:\n\n1.  Get a list of registered `before:response` event listeners.\n2.  For each `before:response` listener (if any), call it with the [`res`](#Intercepted-responses) object.\n    *   If [`res.send()`](#Ending-the-response-with-ressend) is called, end the response phase and merge any passed arguments with the response.\n    *   If a Promise is returned, await it. Merge any modified response properties with the real response.\n3.  If a `req.continue()` with callback is declared for this route, call the callback with the [`res`](#Intercepted-responses) object.\n    *   If [`res.send()`](#Ending-the-response-with-ressend) is called, end the response phase and merge any passed arguments with the response.\n    *   If a Promise is returned, await it. Merge any modified response properties with the real response.\n4.  Get a list of registered `response` event listeners.\n5.  For each `response` listener (if any), call it with the [`res`](#Intercepted-responses) object.\n    *   If [`res.send()`](#Ending-the-response-with-ressend) is called, end the response phase and merge any passed arguments with the response.\n    *   If a Promise is returned, await it. Merge any modified response properties with the real response.\n6.  Send the response to the browser.\n7.  Once the response is complete, get a list of registered `after:response` event listeners.\n8.  For each `after:response` listener (if any), call it with the [`res`](#Intercepted-responses) object (minus `res.send`)\n    *   If a Promise is returned, await it.\n9.  End the response phase.\n",
      "section": "api",
      "anchors": [
        "interception-lifecycle"
      ],
      "path": "/llm/json/chunked/api/commands/intercept.json",
      "token_estimate": 695
    },
    {
      "id": "api/commands/intercept#request-phase",
      "doc_id": "api/commands/intercept",
      "heading": "Request phase​",
      "heading_level": 3,
      "content_markdown": "### Request phase[​](#Request-phase)\n\nThe following steps are used to handle the request phase.\n\n1.  Start with the first matching route according to the above algorithm (middleware first, followed by handlers in reverse order).\n2.  Was a handler (body, [`StaticResponse`](#StaticResponse-objects), or function) supplied to `cy.intercept()`? If not, continue to step 7.\n3.  If the handler was a body or [`StaticResponse`](#StaticResponse-objects), immediately end the request with that response.\n4.  If the handler was a function, call the function with `req`, the incoming request, as the first argument. See [\"Intercepted requests\"](#Intercepted-requests) for more information on the `req` object.\n    *   If [`req.reply()`](#Providing-a-stub-response-with-reqreply) is called, immediately end the request phase with the provided response. See [\"Providing a stub response with `req.reply()`\"](#Providing-a-stub-response-with-reqreply).\n    *   If [`req.continue()`](#Controlling-the-outbound-request-with-reqcontinue) is called, immediately end the request phase, and send the request to the destination server. If a callback is provided to [`req.continue()`](#Controlling-the-outbound-request-with-reqcontinue), it will be called during the [response phase](#Response-phase)\n5.  If the handler returned a Promise, wait for the Promise to resolve.\n6.  Merge any modifications to the request object with the real request.\n7.  If there is another matching `cy.intercept()`, return to step 2 and continue following steps with that route.\n8.  Send the request outgoing to the destination server and end the request phase. The [response phase](#Response-phase) will begin once a response is received.\n",
      "section": "api",
      "anchors": [
        "request-phase"
      ],
      "path": "/llm/json/chunked/api/commands/intercept.json",
      "token_estimate": 288
    },
    {
      "id": "api/commands/intercept#response-phase",
      "doc_id": "api/commands/intercept",
      "heading": "Response phase",
      "heading_level": 3,
      "content_markdown": "### Response phase\n\nOnce the HTTP response is received from the upstream server, the following steps are applied:\n\n1.  Get a list of registered `before:response` event listeners.\n2.  For each `before:response` listener (if any), call it with the [`res`](#Intercepted-responses) object.\n    *   If [`res.send()`](#Ending-the-response-with-ressend) is called, end the response phase and merge any passed arguments with the response.\n    *   If a Promise is returned, await it. Merge any modified response properties with the real response.\n3.  If a `req.continue()` with callback is declared for this route, call the callback with the [`res`](#Intercepted-responses) object.\n    *   If [`res.send()`](#Ending-the-response-with-ressend) is called, end the response phase and merge any passed arguments with the response.\n    *   If a Promise is returned, await it. Merge any modified response properties with the real response.\n4.  Get a list of registered `response` event listeners.\n5.  For each `response` listener (if any), call it with the [`res`](#Intercepted-responses) object.\n    *   If [`res.send()`](#Ending-the-response-with-ressend) is called, end the response phase and merge any passed arguments with the response.\n    *   If a Promise is returned, await it. Merge any modified response properties with the real response.\n6.  Send the response to the browser.\n7.  Once the response is complete, get a list of registered `after:response` event listeners.\n8.  For each `after:response` listener (if any), call it with the [`res`](#Intercepted-responses) object (minus `res.send`)\n    *   If a Promise is returned, await it.\n9.  End the response phase.\n",
      "section": "api",
      "anchors": [
        "response-phase"
      ],
      "path": "/llm/json/chunked/api/commands/intercept.json",
      "token_estimate": 308
    },
    {
      "id": "api/commands/intercept#glob-pattern-matching-urls",
      "doc_id": "api/commands/intercept",
      "heading": "Glob Pattern Matching URLs",
      "heading_level": 2,
      "content_markdown": "## Glob Pattern Matching URLs\n\nWhen [matching a URL](#Matching-url), providing an exact URL to match can be too restrictive. For example, what if you wanted to run your tests on a different host?\n\n```\n// match any request that exactly matches the URLcy.intercept('https://prod.cypress.io/users')// matches this: https://prod.cypress.io/users// ...but not this: https://staging.cypress.io/users// ...or this: http://localhost/users\n```\n\nGlob pattern matching provides the necessary flexibility:\n\n```\ncy.intercept('/users')// matches all of these://   https://prod.cypress.io/users//   https://staging.cypress.io/users//   http://localhost/userscy.intercept('/users?_limit=+(3|5)')// matches all of these://   https://prod.cypress.io/users?_limit=3//   http://localhost/users?_limit=5\n```\n\n### Cypress.minimatch\n\nUnder the hood, `cy.intercept` uses the [minimatch](/llm/markdown/api/utilities/minimatch.md) library with the `{ matchBase: true }` option applied for glob matching and provides access to it via the `Cypress` global. This enables you to test your pattern in your spec or in the Cypress browser console.\n\nYou can invoke the `Cypress.minimatch` with just two arguments - the URL (`string`) and the pattern (`string`), respectively - and if it yields `true`, then you have a match!\n\n```\nexpect(  Cypress.minimatch('http://localhost/users?_limit=3', '**/users?_limit=+(3|5)')).to.be.trueexpect(  Cypress.minimatch('http://localhost/users?_limit=5', '/users?_limit=+(3|5)', {    matchBase: true,  })).to.be.trueexpect(  Cypress.minimatch('http://localhost/users?_limit=7', '**/users?_limit=+(3|5)')).to.be.false\n```\n\n#### minimatch options\n\nYou can also pass in options (`object`) as the third argument, one of which is `debug` which if set to `true`, will yield verbose output that could help you understand why your pattern isn't working as you expect:\n\n```\nCypress.minimatch('http://localhost/users?_limit=3', '**/users?_limit=+(3|5)', {  debug: true,})// true (plus debug messages)\n```\n",
      "section": "api",
      "anchors": [
        "glob-pattern-matching-urls"
      ],
      "path": "/llm/json/chunked/api/commands/intercept.json",
      "token_estimate": 289
    },
    {
      "id": "api/commands/intercept#cypress-minimatch",
      "doc_id": "api/commands/intercept",
      "heading": "Cypress.minimatch",
      "heading_level": 3,
      "content_markdown": "### Cypress.minimatch\n\nUnder the hood, `cy.intercept` uses the [minimatch](/llm/markdown/api/utilities/minimatch.md) library with the `{ matchBase: true }` option applied for glob matching and provides access to it via the `Cypress` global. This enables you to test your pattern in your spec or in the Cypress browser console.\n\nYou can invoke the `Cypress.minimatch` with just two arguments - the URL (`string`) and the pattern (`string`), respectively - and if it yields `true`, then you have a match!\n\n```\nexpect(  Cypress.minimatch('http://localhost/users?_limit=3', '**/users?_limit=+(3|5)')).to.be.trueexpect(  Cypress.minimatch('http://localhost/users?_limit=5', '/users?_limit=+(3|5)', {    matchBase: true,  })).to.be.trueexpect(  Cypress.minimatch('http://localhost/users?_limit=7', '**/users?_limit=+(3|5)')).to.be.false\n```\n\n#### minimatch options\n\nYou can also pass in options (`object`) as the third argument, one of which is `debug` which if set to `true`, will yield verbose output that could help you understand why your pattern isn't working as you expect:\n\n```\nCypress.minimatch('http://localhost/users?_limit=3', '**/users?_limit=+(3|5)', {  debug: true,})// true (plus debug messages)\n```\n",
      "section": "api",
      "anchors": [
        "cypress-minimatch"
      ],
      "path": "/llm/json/chunked/api/commands/intercept.json",
      "token_estimate": 187
    },
    {
      "id": "api/commands/intercept#minimatch-options",
      "doc_id": "api/commands/intercept",
      "heading": "minimatch options",
      "heading_level": 4,
      "content_markdown": "#### minimatch options\n\nYou can also pass in options (`object`) as the third argument, one of which is `debug` which if set to `true`, will yield verbose output that could help you understand why your pattern isn't working as you expect:\n\n```\nCypress.minimatch('http://localhost/users?_limit=3', '**/users?_limit=+(3|5)', {  debug: true,})// true (plus debug messages)\n```\n",
      "section": "api",
      "anchors": [
        "minimatch-options"
      ],
      "path": "/llm/json/chunked/api/commands/intercept.json",
      "token_estimate": 69
    },
    {
      "id": "api/commands/intercept#cy-intercept-and-request-caching",
      "doc_id": "api/commands/intercept",
      "heading": "cy.intercept() and request caching",
      "heading_level": 2,
      "content_markdown": "## `cy.intercept()` and request caching\n\n`cy.intercept()` intercepts requests at the network layer. This can cause confusion when trying to intercept a request that has already been cached by the browser. If a request is served from the browser cache, it will never hit the network layer, and `cy.intercept()` will never fire.\n\nTo see if this is affecting your app, check the Developer Tools. In the following example, all of the requests circled in red have been served from cache, and will not send an HTTP request. Thus, they cannot be intercepted by `cy.intercept()`:\n\nIf you would like to intercept resources that normally send cache headers, here are some workarounds:\n\n*   Turn off cache headers on your development server when in testing mode.\n*   Disable caching on responses by adding a top-level `cy.intercept()` that removes cache headers from desired requests. For example:\n    \n    ```\n    beforeEach(() => {  cy.intercept(    'https://api.example.com/**/*',    { middleware: true },    (req) => {      req.on('before:response', (res) => {        // force all API responses to not be cached        res.headers['cache-control'] = 'no-store'      })    }  )})\n    ```\n    \n*   Chromium-family browsers only: Use `remote:debugger:protocol` to disable cache entirely. For more information, see [this comment on issue #14459](https://github.com/cypress-io/cypress/issues/14459#issuecomment-768616195)\n",
      "section": "api",
      "anchors": [
        "cy-intercept-and-request-caching"
      ],
      "path": "/llm/json/chunked/api/commands/intercept.json",
      "token_estimate": 257
    },
    {
      "id": "api/commands/intercept#command-log",
      "doc_id": "api/commands/intercept",
      "heading": "Command Log",
      "heading_level": 2,
      "content_markdown": "## Command Log\n\n**_Routes Instrument Panel_**\n\nWhen you create `cy.intercept()` rules, Cypress will display a new Instrument called _Routes_.\n\n```\ncy.intercept('/accounts*').as('accountsGet')cy.intercept('/company', { companyId: 1 }).as('companyGet')cy.intercept('/teams*', [{ teamId: 2 }]).as('teamsGet')\n```\n\nIt will list the routing table in the Instrument Panel, including the `method`, `RouteMatcher`, if the route is stubbed, any alias, and number of matched requests:\n\nWhen HTTP requests are made, Cypress will log them in the Command Log and indicate whether they matched a `cy.intercept()` by the presence of a yellow badge on the right hand side:\n\nThe circular indicator is filled if the request went to the destination server, but unfilled if the request was stubbed with a response.\n\nClicking on a request that matched a `cy.intercept()` will print additional information about the request and response to the console:\n\n[Read more about request logging in Cypress.](/llm/markdown/app/guides/network-requests.md#Command-Log)\n",
      "section": "api",
      "anchors": [
        "command-log"
      ],
      "path": "/llm/json/chunked/api/commands/intercept.json",
      "token_estimate": 184
    },
    {
      "id": "api/commands/intercept#history",
      "doc_id": "api/commands/intercept",
      "heading": "History",
      "heading_level": 2,
      "content_markdown": "## History\n\n| Version | Changes |\n| --- | --- |\n| [14.0.0](/llm/markdown/app/references/changelog.md#14-0-0) | Deprecated `resourceType` property |\n| [12.2.0](/llm/markdown/app/references/changelog.md#12-2-0) | Added `resourceType` property to `req` and `RouteMatcher`. |\n| [7.6.0](/llm/markdown/app/references/changelog.md#7-0-0) | Added `query` option to `req` (The incoming request object yielded to request handler functions). |\n| [7.0.0](/llm/markdown/app/references/changelog.md#7-0-0) | Removed `matchUrlAgainstPath` option from `RouteMatcher`, reversed handler ordering, added request events, removed substring URL matching, removed `cy.route2` alias, added `middleware` RouteMatcher option, renamed `res.delay()` to `res.setDelay()` and `res.throttle()` to `res.setThrottle()`. |\n| [6.4.0](/llm/markdown/app/references/changelog.md#6-4-0) | Renamed `delayMs` property to `delay` (backwards-compatible). |\n| [6.2.0](/llm/markdown/app/references/changelog.md#6-2-0) | Added `matchUrlAgainstPath` option to `RouteMatcher`. |\n| [6.0.0](/llm/markdown/app/references/changelog.md#6-0-0) | Renamed `cy.route2()` to `cy.intercept()`. |\n| [6.0.0](/llm/markdown/app/references/changelog.md#6-0-0) | Removed `experimentalNetworkStubbing` option and made it the default behavior. |\n| [5.1.0](/llm/markdown/app/references/changelog.md#5-1-0) | Added experimental `cy.route2()` command under `experimentalNetworkStubbing` option. |\n",
      "section": "api",
      "anchors": [
        "history"
      ],
      "path": "/llm/json/chunked/api/commands/intercept.json",
      "token_estimate": 177
    }
  ]
}