{
  "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": "ce02913654e2655ee63448bdc92bb92c7b46a619",
    "updated_at": "2026-04-22T19:37:51.587Z",
    "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",
        "text": " staticResponse (StaticResponse)",
        "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
      }
    ]
  },
  "content": {
    "type": "root",
    "children": [
      {
        "type": "heading",
        "depth": 1,
        "children": [
          {
            "type": "text",
            "value": "intercept"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Spy and stub network requests and responses."
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Tip: We recommend you read the\n"
          },
          {
            "type": "link",
            "title": null,
            "url": "/llm/markdown/app/guides/network-requests.md",
            "children": [
              {
                "type": "text",
                "value": "Network Requests"
              }
            ]
          },
          {
            "type": "text",
            "value": " guide first."
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "All intercepts are automatically cleared before every test."
          }
        ]
      },
      {
        "type": "heading",
        "depth": 2,
        "children": [
          {
            "type": "text",
            "value": "Syntax"
          }
        ]
      },
      {
        "type": "code",
        "lang": "js",
        "meta": null,
        "value": "// spying only\ncy.intercept(url)\ncy.intercept(method, url)\ncy.intercept(routeMatcher)"
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "See arguments "
          },
          {
            "type": "link",
            "title": null,
            "url": "#url-String-Glob-RegExp",
            "children": [
              {
                "type": "text",
                "value": "url"
              }
            ]
          },
          {
            "type": "text",
            "value": ",\n"
          },
          {
            "type": "link",
            "title": null,
            "url": "#method-String",
            "children": [
              {
                "type": "text",
                "value": "method"
              }
            ]
          },
          {
            "type": "text",
            "value": " and\n"
          },
          {
            "type": "link",
            "title": null,
            "url": "#routeMatcher-RouteMatcher",
            "children": [
              {
                "type": "text",
                "value": "routeMatcher"
              }
            ]
          }
        ]
      },
      {
        "type": "code",
        "lang": "js",
        "meta": null,
        "value": "// spying and response stubbing\ncy.intercept(url, staticResponse)\ncy.intercept(method, url, staticResponse)\ncy.intercept(routeMatcher, staticResponse)\ncy.intercept(url, routeMatcher, staticResponse)"
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "See\n"
          },
          {
            "type": "link",
            "title": null,
            "url": "#staticResponse-StaticResponse",
            "children": [
              {
                "type": "text",
                "value": "staticResponse"
              }
            ]
          },
          {
            "type": "text",
            "value": "\nargument"
          }
        ]
      },
      {
        "type": "code",
        "lang": "js",
        "meta": null,
        "value": "// spying, dynamic stubbing, request modification, etc.\ncy.intercept(url, routeHandler)\ncy.intercept(method, url, routeHandler)\ncy.intercept(routeMatcher, routeHandler)\ncy.intercept(url, routeMatcher, routeHandler)"
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "See\n"
          },
          {
            "type": "link",
            "title": null,
            "url": "#routeHandler-Function",
            "children": [
              {
                "type": "text",
                "value": "routeHandler"
              }
            ]
          },
          {
            "type": "text",
            "value": "\nargument"
          }
        ]
      },
      {
        "type": "code",
        "lang": "typescript",
        "meta": null,
        "value": "// Specifying request and response types\ntype CustomRequest = {\n  kind: 'custom_request'\n}\ntype CustomResponse = {\n  kind: 'custom_response'\n}\ncy.intercept<CustomRequest, CustomResponse>(url, (req) => {\n  req.body // .body of request will be of type CustomRequest\n  req.continue((res) => {\n    res.body // .body of request will be of type CustomResponse\n  })\n})"
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Usage"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Correct Usage"
          }
        ]
      },
      {
        "type": "code",
        "lang": "js",
        "meta": null,
        "value": "// spying\ncy.intercept('/users/**')\ncy.intercept('GET', '/users*')\ncy.intercept({\n  method: 'GET',\n  url: '/users*',\n  hostname: 'localhost',\n})\n\n// spying and response stubbing\ncy.intercept('POST', '/users*', {\n  statusCode: 201,\n  body: {\n    name: 'Peter Pan',\n  },\n})\n\n// spying, dynamic stubbing, request modification, etc.\ncy.intercept('/users*', { hostname: 'localhost' }, (req) => {\n  /* do something with request and/or response */\n})"
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Arguments"
          }
        ]
      },
      {
        "type": "heading",
        "depth": 4,
        "children": [
          {
            "type": "text",
            "value": " method (String)"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Match the route to a specific\n"
          },
          {
            "type": "link",
            "title": null,
            "url": "https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods",
            "children": [
              {
                "type": "text",
                "value": "HTTP method"
              }
            ]
          },
          {
            "type": "text",
            "value": " (`GET`,\n`POST`, `PUT`, etc)."
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "If no method is defined Cypress will match all requests by default."
          }
        ]
      },
      {
        "type": "heading",
        "depth": 4,
        "children": [
          {
            "type": "text",
            "value": " url (String, Glob, RegExp)"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Specify the URL to match. See "
          },
          {
            "type": "linkReference",
            "children": [
              {
                "type": "text",
                "value": "Matching `url`"
              }
            ],
            "label": "match-url",
            "identifier": "match-url",
            "referenceType": "full"
          },
          {
            "type": "text",
            "value": " for examples."
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Alternatively, specify the URL via the "
          },
          {
            "type": "linkReference",
            "children": [
              {
                "type": "text",
                "value": "`routeMatcher`"
              }
            ],
            "label": "arg-routematcher",
            "identifier": "arg-routematcher",
            "referenceType": "full"
          },
          {
            "type": "text",
            "value": "\nargument (below)."
          }
        ]
      },
      {
        "type": "heading",
        "depth": 4,
        "children": [
          {
            "type": "text",
            "value": " routeMatcher (RouteMatcher)"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "`routeMatcher` is an object used to match the incoming HTTP requests with this\nintercepted route."
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "All properties are optional but all those that are set must match for the\nrequest to be intercepted. If a `string` is passed to any property, it will be\nglob-matched against the request using\n"
          },
          {
            "type": "link",
            "title": null,
            "url": "/llm/markdown/api/utilities/minimatch.md",
            "children": [
              {
                "type": "text",
                "value": "`Cypress.minimatch`"
              }
            ]
          },
          {
            "type": "text",
            "value": " with the `{ matchBase: true }`\nminimatch option applied."
          }
        ]
      },
      {
        "type": "table",
        "align": [
          null,
          null
        ],
        "children": [
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Option"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Description"
                  }
                ]
              }
            ]
          },
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "auth"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "HTTP Basic Authentication (`object` with keys `username` and `password`)"
                  }
                ]
              }
            ]
          },
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "headers"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "HTTP request headers (`object`)"
                  }
                ]
              }
            ]
          },
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "hostname"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "HTTP request hostname"
                  }
                ]
              }
            ]
          },
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "https"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "`true`: only secure (https://) requests, `false`: only insecure (http://) requests"
                  }
                ]
              }
            ]
          },
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "method"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "HTTP request method (matches any method by default)"
                  }
                ]
              }
            ]
          },
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "middleware"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "`true`: match route first and in defined order, `false`: match route in reverse order (default)"
                  }
                ]
              }
            ]
          },
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "path"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "HTTP request path after the hostname, including query parameters"
                  }
                ]
              }
            ]
          },
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "pathname"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Like `path`, but without query parameters"
                  }
                ]
              }
            ]
          },
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "port"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "HTTP request port(s) (`number` or `Array`)"
                  }
                ]
              }
            ]
          },
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "query"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Parsed query string (`object`)"
                  }
                ]
              }
            ]
          },
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "resourceType"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "The resource type of the request. See "
                  },
                  {
                    "type": "link",
                    "title": null,
                    "url": "#Request-object-properties",
                    "children": [
                      {
                        "type": "text",
                        "value": "\"Request object properties\""
                      }
                    ]
                  },
                  {
                    "type": "text",
                    "value": " for a list of possible values for `resourceType`."
                  }
                ]
              }
            ]
          },
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "times"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Maximum number of times to match (`number`)"
                  }
                ]
              }
            ]
          },
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "url"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Full HTTP request URL"
                  }
                ]
              }
            ]
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "See "
          },
          {
            "type": "link",
            "title": null,
            "url": "#With-RouteMatcher",
            "children": [
              {
                "type": "text",
                "value": "examples"
              }
            ]
          },
          {
            "type": "text",
            "value": " below."
          }
        ]
      },
      {
        "type": "heading",
        "depth": 4,
        "children": [
          {
            "type": "text",
            "value": " staticResponse (StaticResponse)"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "By passing in a `StaticResponse` as the last argument, you can\n"
          },
          {
            "type": "link",
            "title": null,
            "url": "#Stubbing-a-response",
            "children": [
              {
                "type": "text",
                "value": "statically define (stub) a response"
              }
            ]
          },
          {
            "type": "text",
            "value": " for matched\nrequests. See "
          },
          {
            "type": "link",
            "title": null,
            "url": "#StaticResponse-objects",
            "children": [
              {
                "type": "text",
                "value": "`StaticResponse` object"
              }
            ]
          },
          {
            "type": "text",
            "value": " for the list of\nproperties."
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Additionally, you can pass `{ log: false }` with your `StaticResponse` to\ndisable command logs for this intercept. See\n"
          },
          {
            "type": "link",
            "title": null,
            "url": "#Disabling-logs-for-a-request",
            "children": [
              {
                "type": "text",
                "value": "\"Disabling logs for a request\""
              }
            ]
          },
          {
            "type": "text",
            "value": "."
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "See\n"
          },
          {
            "type": "link",
            "title": null,
            "url": "#With-a-StaticResponse-object",
            "children": [
              {
                "type": "text",
                "value": "Stubbing a response with a `StaticResponse` object"
              }
            ]
          },
          {
            "type": "text",
            "value": "\nfor an example."
          }
        ]
      },
      {
        "type": "heading",
        "depth": 4,
        "children": [
          {
            "type": "text",
            "value": " routeHandler (Function)"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "The `routeHandler` function is called whenever a request is matched, with the\nfirst argument being the request object. From inside the callback, you have\naccess to the entire request-response where you can modify the outgoing request,\nsend a response, access the real response, and more."
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "See "
          },
          {
            "type": "linkReference",
            "children": [
              {
                "type": "text",
                "value": "\"Intercepted requests\""
              }
            ],
            "label": "req",
            "identifier": "req",
            "referenceType": "full"
          },
          {
            "type": "text",
            "value": " and\n"
          },
          {
            "type": "link",
            "title": null,
            "url": "#RequestResponse-Modification-with-routeHandler",
            "children": [
              {
                "type": "text",
                "value": "Request/Response Modification with `routeHandler`"
              }
            ]
          },
          {
            "type": "text",
            "value": "."
          }
        ]
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Yields "
          },
          {
            "type": "link",
            "title": null,
            "url": "/llm/markdown/app/core-concepts/introduction-to-cypress.md#Subject-Management",
            "children": [
              {
                "type": "text",
                "value": "Learn about subject management"
              }
            ]
          }
        ]
      },
      {
        "type": "list",
        "ordered": false,
        "start": null,
        "spread": false,
        "children": [
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "`cy.intercept()` yields `null`, but can be aliased."
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "Waiting on an aliased `cy.intercept()` route using\n"
                  },
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/api/commands/wait.md",
                    "children": [
                      {
                        "type": "text",
                        "value": "cy.wait()"
                      }
                    ]
                  },
                  {
                    "type": "text",
                    "value": " will yield an object that contains information\nabout the matching request/response cycle. See\n"
                  },
                  {
                    "type": "link",
                    "title": null,
                    "url": "#Using-the-yielded-object",
                    "children": [
                      {
                        "type": "text",
                        "value": "Using the yielded object"
                      }
                    ]
                  },
                  {
                    "type": "text",
                    "value": " for examples of how to\nuse this object."
                  }
                ]
              }
            ]
          }
        ]
      },
      {
        "type": "heading",
        "depth": 2,
        "children": [
          {
            "type": "text",
            "value": "Examples"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "`cy.intercept` can be used solely for spying: to passively listen for matching\nroutes and apply "
          },
          {
            "type": "link",
            "title": null,
            "url": "#Aliasing-an-intercepted-route",
            "children": [
              {
                "type": "text",
                "value": "aliases"
              }
            ]
          },
          {
            "type": "text",
            "value": " to them without manipulating the\nrequest or its response in any way. This alone is powerful as it allows you to\n"
          },
          {
            "type": "link",
            "title": null,
            "url": "#Waiting-on-a-request",
            "children": [
              {
                "type": "text",
                "value": "wait"
              }
            ]
          },
          {
            "type": "text",
            "value": " for these requests, resulting in more reliable\ntests."
          }
        ]
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Matching url"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "You can provide the exact "
          },
          {
            "type": "link",
            "title": null,
            "url": "#Arguments",
            "children": [
              {
                "type": "text",
                "value": "URL"
              }
            ]
          },
          {
            "type": "text",
            "value": " to match or use pattern-matching to\nmatch many URLs at once, either with globs or with regex. See\n"
          },
          {
            "type": "link",
            "title": null,
            "url": "#Glob-Pattern-Matching-URLs",
            "children": [
              {
                "type": "text",
                "value": "Glob Pattern Matching URLs"
              }
            ]
          },
          {
            "type": "text",
            "value": "."
          }
        ]
      },
      {
        "type": "code",
        "lang": "js",
        "meta": null,
        "value": "// match any request that exactly matches the URL\ncy.intercept('https://prod.cypress.io/users')\n\n// match any request that satisfies a glob pattern\ncy.intercept('/users?_limit=*')\n\n// match any request that satisfies a regex pattern\ncy.intercept(/\\/users\\?_limit=(3|5)$/)"
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Matching method"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "If you don't pass in a "
          },
          {
            "type": "linkReference",
            "children": [
              {
                "type": "text",
                "value": "`method` argument"
              }
            ],
            "label": "arg-method",
            "identifier": "arg-method",
            "referenceType": "full"
          },
          {
            "type": "text",
            "value": ", then all HTTP methods\n(`GET`, `POST`, `PUT`, `PATCH`, `DELETE`, etc.) will match."
          }
        ]
      },
      {
        "type": "code",
        "lang": "js",
        "meta": null,
        "value": "cy.intercept('/users')\n// matches this: GET http://localhost/users\n// ...and this, too: POST http://localhost/users\n\ncy.intercept('GET', '/users')\n// matches this: GET http://localhost/users\n// ...but not this: POST http://localhost/users"
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Matching with "
          },
          {
            "type": "link",
            "title": null,
            "url": "#routeMatcher-RouteMatcher",
            "children": [
              {
                "type": "text",
                "value": "RouteMatcher"
              }
            ]
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Specifying a `method` and `url` to match can also be acheived by passing the\n`routeMatcher` object into `cy.intercept` instead:"
          }
        ]
      },
      {
        "type": "code",
        "lang": "js",
        "meta": null,
        "value": "// These both yield the same result:\ncy.intercept({ method: 'GET', url: '**/users' })\ncy.intercept('GET', '**/users')"
      },
      {
        "type": "code",
        "lang": "js",
        "meta": null,
        "value": "// Match any type of request with the pathname `/search`\n// and the query parameter 'q=some+terms'\ncy.intercept({\n  pathname: '/search',\n  query: {\n    q: 'some terms',\n  },\n}).as('searchForTerms')"
      },
      {
        "type": "code",
        "lang": "js",
        "meta": null,
        "value": "cy.intercept(\n  {\n    // this RegExp matches any URL beginning with\n    // 'http://api.example.com/' and ending with '/edit' or '/save'\n    url: /^http:\\/\\/api\\.example\\.com\\/.*\\/(edit|save)/,\n    // matching requests must also contain this header\n    headers: {\n      'x-requested-with': 'exampleClient',\n    },\n  }\n})"
      },
      {
        "type": "code",
        "lang": "js",
        "meta": null,
        "value": "// this example will cause 1 request to `/temporary-error`\n// to receive a network error and subsequent requests will\n// not match this `RouteMatcher`\ncy.intercept({ url: '/temporary-error', times: 1 }, { forceNetworkError: true })"
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Pattern Matching"
          }
        ]
      },
      {
        "type": "code",
        "lang": "js",
        "meta": null,
        "value": "// match updates to the `/users` endpoint using glob matching\ncy.intercept({\n  method: '+(PUT|PATCH)',\n  url: '**/users/*',\n})\n// matches:\n//   PUT /users/1\n//   PATCH /users/1\n//\n// doesn't match:\n//   GET /users\n//   GET /users/1\n\n// same as above, but using regex\ncy.intercept({\n  method: '/PUT|PATCH/',\n  url: '**/users/*',\n})"
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Aliasing an intercepted route"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "While `cy.intercept` doesn't yield anything, you can chain\n"
          },
          {
            "type": "link",
            "title": null,
            "url": "/llm/markdown/api/commands/as.md",
            "children": [
              {
                "type": "text",
                "value": "`.as`"
              }
            ]
          },
          {
            "type": "text",
            "value": " to it to create an\n"
          },
          {
            "type": "link",
            "title": null,
            "url": "/llm/markdown/app/core-concepts/variables-and-aliases.md#Aliases",
            "children": [
              {
                "type": "text",
                "value": "alias"
              }
            ]
          },
          {
            "type": "text",
            "value": " which can be used\nto "
          },
          {
            "type": "link",
            "title": null,
            "url": "#Waiting-on-a-request",
            "children": [
              {
                "type": "text",
                "value": "wait on a request"
              }
            ]
          },
          {
            "type": "text",
            "value": "."
          }
        ]
      },
      {
        "type": "code",
        "lang": "js",
        "meta": null,
        "value": "cy.intercept('GET', '/users').as('getAllUsers')\ncy.intercept('POST', '/users').as('createUser')"
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Aliasing individual requests"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Aliases can be set on a per-request basis by setting the `alias` property of the\nintercepted request. This is especially useful when intercepting GraphQL\nrequests:"
          }
        ]
      },
      {
        "type": "code",
        "lang": "js",
        "meta": null,
        "value": "cy.intercept('POST', '/graphql', (req) => {\n  if (req.body.hasOwnProperty('query') && req.body.query.includes('mutation')) {\n    req.alias = 'gqlMutation'\n  }\n})\n\n// assert that a matching request has been made\ncy.wait('@gqlMutation')"
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "For more guidance around aliasing requests with GraphQL, see\n"
          },
          {
            "type": "link",
            "title": null,
            "url": "/llm/markdown/app/guides/network-requests.md#Working-with-GraphQL",
            "children": [
              {
                "type": "text",
                "value": "Working with GraphQL"
              }
            ]
          },
          {
            "type": "text",
            "value": "."
          }
        ]
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Waiting on a request"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Use "
          },
          {
            "type": "link",
            "title": null,
            "url": "/llm/markdown/api/commands/wait.md",
            "children": [
              {
                "type": "text",
                "value": "cy.wait()"
              }
            ]
          },
          {
            "type": "text",
            "value": " with\n"
          },
          {
            "type": "link",
            "title": null,
            "url": "#Aliasing-an-intercepted-route",
            "children": [
              {
                "type": "text",
                "value": "aliasing an intercepted route"
              }
            ]
          },
          {
            "type": "text",
            "value": " to wait for the\nrequest/response cycle to complete."
          }
        ]
      },
      {
        "type": "heading",
        "depth": 4,
        "children": [
          {
            "type": "text",
            "value": "With URL"
          }
        ]
      },
      {
        "type": "code",
        "lang": "js",
        "meta": null,
        "value": "cy.intercept('http://example.com/settings').as('getSettings')\n\n// once a request to get settings responds, 'cy.wait' will resolve\ncy.wait('@getSettings')"
      },
      {
        "type": "heading",
        "depth": 4,
        "children": [
          {
            "type": "text",
            "value": "With "
          },
          {
            "type": "link",
            "title": null,
            "url": "#routeMatcher-RouteMatcher",
            "children": [
              {
                "type": "text",
                "value": "RouteMatcher"
              }
            ]
          }
        ]
      },
      {
        "type": "code",
        "lang": "js",
        "meta": null,
        "value": "cy.intercept({\n  url: 'http://example.com/search*',\n  query: { q: 'expected terms' },\n}).as('search')\n\n// once any type of request to search with a querystring\n// containing 'q=expected+terms' responds, 'cy.wait' will resolve\ncy.wait('@search')"
      },
      {
        "type": "heading",
        "depth": 4,
        "children": [
          {
            "type": "text",
            "value": "Using the yielded object"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Using "
          },
          {
            "type": "link",
            "title": null,
            "url": "/llm/markdown/api/commands/wait.md",
            "children": [
              {
                "type": "text",
                "value": "cy.wait()"
              }
            ]
          },
          {
            "type": "text",
            "value": " on a `cy.intercept()` route alias yields\nan interception object which represents the request/response cycle:"
          }
        ]
      },
      {
        "type": "code",
        "lang": "js",
        "meta": null,
        "value": "cy.wait('@someRoute').then((interception) => {\n  // 'interception' is an object with properties\n  // 'id', 'request' and 'response'\n})"
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "You can chain "
          },
          {
            "type": "link",
            "title": null,
            "url": "/llm/markdown/api/commands/its.md",
            "children": [
              {
                "type": "text",
                "value": "`.its()`"
              }
            ]
          },
          {
            "type": "text",
            "value": " and\n"
          },
          {
            "type": "link",
            "title": null,
            "url": "/llm/markdown/api/commands/should.md",
            "children": [
              {
                "type": "text",
                "value": "`.should()`"
              }
            ]
          },
          {
            "type": "text",
            "value": " to assert against request/response cycles:"
          }
        ]
      },
      {
        "type": "code",
        "lang": "js",
        "meta": null,
        "value": "// assert that a request to this route\n// was made with a body that included 'user'\ncy.wait('@someRoute').its('request.body').should('include', 'user')\n\n// assert that a request to this route\n// received a response with HTTP status 500\ncy.wait('@someRoute').its('response.statusCode').should('eq', 500)\n\n// assert that a request to this route\n// received a response body that includes 'id'\ncy.wait('@someRoute').its('response.body').should('include', 'id')"
      },
      {
        "type": "heading",
        "depth": 4,
        "children": [
          {
            "type": "text",
            "value": "Waiting on errors"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "You can use "
          },
          {
            "type": "link",
            "title": null,
            "url": "/llm/markdown/api/commands/wait.md",
            "children": [
              {
                "type": "text",
                "value": "cy.wait()"
              }
            ]
          },
          {
            "type": "text",
            "value": " to wait on requests that end with\nnetwork errors:"
          }
        ]
      },
      {
        "type": "code",
        "lang": "js",
        "meta": null,
        "value": "cy.intercept('GET', '/should-err', { forceNetworkError: true }).as('err')\n\n// assert that this request happened\n// and that it ended in an error\ncy.wait('@err').should('have.property', 'error')"
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Stubbing a response"
          }
        ]
      },
      {
        "type": "heading",
        "depth": 4,
        "children": [
          {
            "type": "text",
            "value": "With a string"
          }
        ]
      },
      {
        "type": "code",
        "lang": "js",
        "meta": null,
        "value": "// requests to '/update' will be fulfilled\n// with a body of \"success\"\ncy.intercept('/update', 'success')"
      },
      {
        "type": "heading",
        "depth": 4,
        "children": [
          {
            "type": "text",
            "value": "With a fixture"
          }
        ]
      },
      {
        "type": "code",
        "lang": "js",
        "meta": null,
        "value": "// requests to '/users.json' will be fulfilled\n// with the contents of the \"users.json\" fixture\ncy.intercept('/users.json', { fixture: 'users.json' })"
      },
      {
        "type": "heading",
        "depth": 4,
        "children": [
          {
            "type": "text",
            "value": "With a StaticResponse object"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "A "
          },
          {
            "type": "linkReference",
            "children": [
              {
                "type": "text",
                "value": "`StaticResponse`"
              }
            ],
            "label": "staticresponse",
            "identifier": "staticresponse",
            "referenceType": "full"
          },
          {
            "type": "text",
            "value": " object represents a response to an HTTP\nrequest, and can be used to stub routes:"
          }
        ]
      },
      {
        "type": "code",
        "lang": "js",
        "meta": null,
        "value": "const staticResponse = {\n  /* some StaticResponse properties here... */\n}\n\ncy.intercept('/projects', staticResponse)"
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Stub a response with a JSON body:"
          }
        ]
      },
      {
        "type": "code",
        "lang": "js",
        "meta": null,
        "value": "cy.intercept('/projects', {\n  body: [{ projectId: '1' }, { projectId: '2' }],\n})"
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Stub headers, status code, and body all at once:"
          }
        ]
      },
      {
        "type": "code",
        "lang": "js",
        "meta": null,
        "value": "cy.intercept('/not-found', {\n  statusCode: 404,\n  body: '404 Not Found!',\n  headers: {\n    'x-not-found': 'true',\n  },\n})"
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Stub response with a fixture that is read as a Buffer:"
          }
        ]
      },
      {
        "type": "code",
        "lang": "js",
        "meta": null,
        "value": "cy.intercept('/not-found', {\n  fixture: 'media/gif.mp4,null',\n})"
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "See also "
          },
          {
            "type": "linkReference",
            "children": [
              {
                "type": "text",
                "value": "`StaticResponse` object"
              }
            ],
            "label": "staticresponse",
            "identifier": "staticresponse",
            "referenceType": "full"
          },
          {
            "type": "text",
            "value": "."
          }
        ]
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Using the routeHandler function"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "By specifying a "
          },
          {
            "type": "linkReference",
            "children": [
              {
                "type": "text",
                "value": "`routeHandler`"
              }
            ],
            "label": "arg-routehandler",
            "identifier": "arg-routehandler",
            "referenceType": "full"
          },
          {
            "type": "text",
            "value": " function as the last argument\nto `cy.intercept`, you'll have access to the entire request-response session,\nenabling you to modify the outgoing request, manipulate the real response, make\nassertions, etc."
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "The `routeHandler` takes the incoming HTTP request (`IncomingHTTPRequest`) as\nthe first argument."
          }
        ]
      },
      {
        "type": "code",
        "lang": "js",
        "meta": null,
        "value": "cy.intercept('/users*', (req) => {\n  /* do something with request and/or response */\n})"
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Throughout these examples we will refer to the incoming HTTP request as `req`.\nThose of you with "
          },
          {
            "type": "link",
            "title": null,
            "url": "https://expressjs.com/",
            "children": [
              {
                "type": "text",
                "value": "Express.js"
              }
            ]
          },
          {
            "type": "text",
            "value": "\n"
          },
          {
            "type": "link",
            "title": null,
            "url": "https://expressjs.com/en/guide/writing-middleware.html",
            "children": [
              {
                "type": "text",
                "value": "middleware"
              }
            ]
          },
          {
            "type": "text",
            "value": " experience\nshould be familiar with this syntax."
          }
        ]
      },
      {
        "type": "heading",
        "depth": 4,
        "children": [
          {
            "type": "text",
            "value": "Asserting on a request"
          }
        ]
      },
      {
        "type": "code",
        "lang": "js",
        "meta": null,
        "value": "cy.intercept('POST', '/organization', (req) => {\n  expect(req.body).to.include('Acme Company')\n})"
      },
      {
        "type": "heading",
        "depth": 4,
        "children": [
          {
            "type": "text",
            "value": "Modifying an outgoing request"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "You can use the request handler callback to modify the "
          },
          {
            "type": "linkReference",
            "children": [
              {
                "type": "text",
                "value": "intercepted request\nobject"
              }
            ],
            "label": "req",
            "identifier": "req",
            "referenceType": "full"
          },
          {
            "type": "text",
            "value": " before it is sent."
          }
        ]
      },
      {
        "type": "code",
        "lang": "js",
        "meta": null,
        "value": "// set the request body to something different\n// before it's sent to the destination\ncy.intercept('POST', '/login', (req) => {\n  req.body = 'username=janelane&password=secret123'\n})\n\n// dynamically set the alias\ncy.intercept('POST', '/login', (req) => {\n  req.alias = 'login'\n})"
      },
      {
        "type": "heading",
        "depth": 4,
        "children": [
          {
            "type": "text",
            "value": "Adding a header to an outgoing request"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "You can add a header to an outgoing request, or modify an existing header"
          }
        ]
      },
      {
        "type": "code",
        "lang": "js",
        "meta": null,
        "value": "cy.intercept('/req-headers', (req) => {\n  req.headers['x-custom-headers'] = 'added by cy.intercept'\n})"
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Note: the new header will NOT be shown in the browser's Network tab, as the\nrequest has already left the browser. You can still confirm the header was added\nby waiting on the intercept as shown below:"
          }
        ]
      },
      {
        "type": "heading",
        "depth": 4,
        "children": [
          {
            "type": "text",
            "value": "Waiting on the intercept"
          }
        ]
      },
      {
        "type": "code",
        "lang": "js",
        "meta": null,
        "value": "cy.intercept('/req-headers', (req) => {\n  req.headers['x-custom-headers'] = 'added by cy.intercept'\n}).as('headers')\n\n// the application makes the call ...\n// confirm the custom header was added\ncy.wait('@headers')\n  .its('request.headers')\n  .should('have.property', 'x-custom-headers', 'added by cy.intercept')"
      },
      {
        "type": "heading",
        "depth": 4,
        "children": [
          {
            "type": "text",
            "value": "Add, modify or delete a header to all outgoing requests"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "You can add, modify or delete a header to all outgoing requests using a\n`beforeEach()` in the\n"
          },
          {
            "type": "link",
            "title": null,
            "url": "/llm/markdown/app/core-concepts/writing-and-organizing-tests.md#Support-file",
            "children": [
              {
                "type": "text",
                "value": "supportFile"
              }
            ]
          },
          {
            "type": "text",
            "value": "."
          }
        ]
      },
      {
        "type": "code",
        "lang": "js",
        "meta": null,
        "value": "beforeEach(() => {\n  cy.intercept(\n    { url: 'http://localhost:3001/**', middleware: true },\n    // Delete 'if-none-match' header from all outgoing requests\n    (req) => delete req.headers['if-none-match']\n  )\n})"
      },
      {
        "type": "heading",
        "depth": 4,
        "children": [
          {
            "type": "text",
            "value": "Dynamically stubbing a response"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "You can use the "
          },
          {
            "type": "linkReference",
            "children": [
              {
                "type": "text",
                "value": "`req.reply()`"
              }
            ],
            "label": "req-reply",
            "identifier": "req-reply",
            "referenceType": "full"
          },
          {
            "type": "text",
            "value": " function to dynamically control the\nresponse to a request."
          }
        ]
      },
      {
        "type": "code",
        "lang": "js",
        "meta": null,
        "value": "cy.intercept('/billing', (req) => {\n  // functions on 'req' can be used to\n  // dynamically respond to a request here\n\n  // send the request to the destination server\n  req.reply()\n\n  // respond to the request with a JSON object\n  req.reply({ plan: 'starter' })\n\n  // send the request to the destination server\n  // and intercept the response\n  req.continue((res) => {\n    // 'res' represents the real destination's response\n    // See \"Intercepting a response\" for more details and examples\n  })\n})"
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "See "
          },
          {
            "type": "linkReference",
            "children": [
              {
                "type": "text",
                "value": "\"Intercepted requests\""
              }
            ],
            "label": "req",
            "identifier": "req",
            "referenceType": "full"
          },
          {
            "type": "text",
            "value": " for more information on the `req` object and\nits properties and methods."
          }
        ]
      },
      {
        "type": "heading",
        "depth": 4,
        "children": [
          {
            "type": "text",
            "value": "Returning a Promise"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "If a Promise is returned from the route callback, it will be awaited before\ncontinuing with the request."
          }
        ]
      },
      {
        "type": "code",
        "lang": "js",
        "meta": null,
        "value": "cy.intercept('POST', '/login', (req) => {\n  // you could asynchronously fetch test data...\n  return getLoginCredentials().then((credentials) => {\n    // ...and then, use it to supplement the outgoing request\n    req.headers['authorization'] = credentials\n  })\n})"
      },
      {
        "type": "heading",
        "depth": 4,
        "children": [
          {
            "type": "text",
            "value": "Passing a request to the next request handler"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "If "
          },
          {
            "type": "linkReference",
            "children": [
              {
                "type": "text",
                "value": "`req.reply()`"
              }
            ],
            "label": "req-reply",
            "identifier": "req-reply",
            "referenceType": "full"
          },
          {
            "type": "text",
            "value": " or "
          },
          {
            "type": "linkReference",
            "children": [
              {
                "type": "text",
                "value": "`req.continue()`"
              }
            ],
            "label": "req-continue",
            "identifier": "req-continue",
            "referenceType": "full"
          },
          {
            "type": "text",
            "value": " is not\nexplicitly called inside of a request handler, requests will pass to the next\nrequest handler until none are left."
          }
        ]
      },
      {
        "type": "code",
        "lang": "js",
        "meta": null,
        "value": "// you could have a top-level middleware handler that\n// sets an auth token on all requests\n// but remember setting `middleware: true` will\n// cause this to always be called first\ncy.intercept('http://api.company.com/', { middleware: true }, (req) => {\n  req.headers['authorization'] = `token ${token}`\n})\n\n// and then have another handler that\n// more narrowly asserts on certain requests\ncy.intercept('POST', 'http://api.company.com/widgets', (req) => {\n  expect(req.body).to.include('analytics')\n})\n\n// a POST request to http://api.company.com/widgets would hit both\n// of those callbacks, middleware first, then the request would be\n// sent out with the modified request headers to the\n// real destination"
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Disabling logs for a request"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "By default, Cypress logs all requests that match any `cy.intercept()`, as well\nas all `XMLHttpRequest`s and `fetch` requests. You can use `cy.intercept()` to\ndisable these logs by passing `{ log: false }` in the second parameter:"
          }
        ]
      },
      {
        "type": "code",
        "lang": "js",
        "meta": null,
        "value": "// disable Cypress's default behavior of logging all XMLHttpRequests and fetches\ncy.intercept({ resourceType: /xhr|fetch/ }, { log: false })"
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Note: Currently, you can only enable/disable a request's logs when defining the\n`cy.intercept()`, not inside of an `intercept` callback. See\n"
          },
          {
            "type": "link",
            "title": null,
            "url": "https://github.com/cypress-io/cypress/issues/26069",
            "children": [
              {
                "type": "text",
                "value": "#26069"
              }
            ]
          },
          {
            "type": "text",
            "value": "."
          }
        ]
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Intercepting a response"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Inside of a callback passed to `req.continue()`, you can access the destination\nserver's real response."
          }
        ]
      },
      {
        "type": "code",
        "lang": "js",
        "meta": null,
        "value": "cy.intercept('/integrations', (req) => {\n  // req.continue() with a callback will send the request to\n  // the destination server\n  req.continue((res) => {\n    // 'res' represents the real destination response\n    // you can manipulate 'res' before it's sent to the browser\n  })\n})"
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "See "
          },
          {
            "type": "linkReference",
            "children": [
              {
                "type": "text",
                "value": "\"Intercepted responses\""
              }
            ],
            "label": "res",
            "identifier": "res",
            "referenceType": "full"
          },
          {
            "type": "text",
            "value": " for more information on the `res` object. See\n"
          },
          {
            "type": "linkReference",
            "children": [
              {
                "type": "text",
                "value": "\"Controlling the outbound request with `req.continue()`\""
              }
            ],
            "label": "req-continue",
            "identifier": "req-continue",
            "referenceType": "full"
          },
          {
            "type": "text",
            "value": " for\nmore information about `req.continue()`."
          }
        ]
      },
      {
        "type": "heading",
        "depth": 4,
        "children": [
          {
            "type": "text",
            "value": "Asserting on a response"
          }
        ]
      },
      {
        "type": "code",
        "lang": "js",
        "meta": null,
        "value": "cy.intercept('/projects/2', (req) => {\n  req.continue((res) => {\n    expect(res.body).to.include('My Project')\n  })\n})"
      },
      {
        "type": "heading",
        "depth": 4,
        "children": [
          {
            "type": "text",
            "value": "Returning a Promise"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "If a Promise is returned from the route callback, it will be awaited before\nsending the response to the browser."
          }
        ]
      },
      {
        "type": "code",
        "lang": "js",
        "meta": null,
        "value": "cy.intercept('/users', (req) => {\n  req.continue((res) => {\n    // the response will not be sent to the browser until\n    // 'waitForSomething()' resolves\n    return waitForSomething()\n  })\n})"
      },
      {
        "type": "heading",
        "depth": 4,
        "children": [
          {
            "type": "text",
            "value": "Throttle or delay response all incoming responses"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "You can throttle or delay all incoming responses using a `beforeEach()` in the\n"
          },
          {
            "type": "link",
            "title": null,
            "url": "/llm/markdown/app/core-concepts/writing-and-organizing-tests.md#Support-file",
            "children": [
              {
                "type": "text",
                "value": "supportFile"
              }
            ]
          },
          {
            "type": "text",
            "value": "."
          }
        ]
      },
      {
        "type": "code",
        "lang": "js",
        "meta": null,
        "value": "// Throttle API responses to simulate real-world conditions\nbeforeEach(() => {\n  cy.intercept(\n    {\n      url: 'http://localhost:3001/**',\n      middleware: true,\n    },\n    (req) => {\n      req.on('response', (res) => {\n        // Throttle the response to 1 Mbps to simulate a\n        // mobile 3G connection\n        res.setThrottle(1000)\n      })\n    }\n  )\n})"
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Request/Response Modification with routeHandler"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Specify "
          },
          {
            "type": "linkReference",
            "children": [
              {
                "type": "text",
                "value": "`routeHandler`"
              }
            ],
            "label": "arg-routehandler",
            "identifier": "arg-routehandler",
            "referenceType": "full"
          },
          {
            "type": "text",
            "value": " as the last argument to modify the\noutgoing request, stub a response, make assertions, etc."
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "/* TODO DX-188 emphasize the usage of StaticResponse as the routeHandler */"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "If a function is passed as the `routeHandler`, it will be called with the\nintercepted HTTP request:"
          }
        ]
      },
      {
        "type": "code",
        "lang": "js",
        "meta": null,
        "value": "cy.intercept('/api', (req) => {\n  // do something with the intercepted request\n})"
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "From here, you can do several things with the intercepted request:"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "/* TODO DX-190 add links to examples */"
          }
        ]
      },
      {
        "type": "list",
        "ordered": false,
        "start": null,
        "spread": false,
        "children": [
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "modify and make assertions on the request like its body, headers, URL, method,\netc. ("
                  },
                  {
                    "type": "link",
                    "title": null,
                    "url": "#Asserting-on-a-request-1",
                    "children": [
                      {
                        "type": "text",
                        "value": "example"
                      }
                    ]
                  },
                  {
                    "type": "text",
                    "value": ")"
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "stub out the response without interacting with a real back-end\n("
                  },
                  {
                    "type": "link",
                    "title": null,
                    "url": "#Controlling-the-response",
                    "children": [
                      {
                        "type": "text",
                        "value": "example"
                      }
                    ]
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "pass the request through to its destination and modify or make assertions on\nthe real response on its way back ("
                  },
                  {
                    "type": "link",
                    "title": null,
                    "url": "#Controlling-the-response",
                    "children": [
                      {
                        "type": "text",
                        "value": "example"
                      }
                    ]
                  },
                  {
                    "type": "text",
                    "value": ")"
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "attach listeners to various events on the request\n("
                  },
                  {
                    "type": "link",
                    "title": null,
                    "url": "#Controlling-the-response",
                    "children": [
                      {
                        "type": "text",
                        "value": "example"
                      }
                    ]
                  },
                  {
                    "type": "text",
                    "value": ")"
                  }
                ]
              }
            ]
          }
        ]
      },
      {
        "type": "heading",
        "depth": 4,
        "children": [
          {
            "type": "text",
            "value": "Asserting on a request"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "You can use the request handler callback to make an assertion on the\n"
          },
          {
            "type": "linkReference",
            "children": [
              {
                "type": "text",
                "value": "intercepted request object"
              }
            ],
            "label": "req",
            "identifier": "req",
            "referenceType": "full"
          },
          {
            "type": "text",
            "value": " before it is sent."
          }
        ]
      },
      {
        "type": "code",
        "lang": "js",
        "meta": null,
        "value": "// match requests to create a user\ncy.intercept('POST', '/users', (req) => {\n  // make an assertion on the payload contents\n  expect(req.body).to.include('Peter Pan')\n})"
      },
      {
        "type": "heading",
        "depth": 4,
        "children": [
          {
            "type": "text",
            "value": "Controlling the outgoing request"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "The outgoing request, including its body, headers, etc., can be modified before\nit's sent."
          }
        ]
      },
      {
        "type": "code",
        "lang": "js",
        "meta": null,
        "value": "// modify the request body before it's sent to its destination\ncy.intercept('POST', '/users', (req) => {\n  req.body = {\n    name: 'Peter Pan',\n  }\n})\n\n// add a header to an outgoing request\ncy.intercept('POST', '/users', (req) => {\n  req.headers['x-custom-header'] = 'added by cy.intercept'\n})\n\n// modify an existing header\ncy.intercept('POST', '/users', (req) => {\n  req.headers['authorization'] = 'Basic YWxhZGRpbjpvcGVuc2VzYW1l'\n})"
      },
      {
        "type": "heading",
        "depth": 4,
        "children": [
          {
            "type": "text",
            "value": "Verifying the request modification"
          }
        ]
      },
      {
        "type": "code",
        "lang": "js",
        "meta": null,
        "value": "cy.intercept('POST', '/users', (req) => {\n  req.headers['x-custom-header'] = 'added by cy.intercept'\n}).as('createUser')\n\ncy.get('button.save').click()\n// you can see the headers in the console output by selecting\n// this line in the command log:\ncy.wait('@createUser')\n  // ...or make an assertion:\n  .its('request.headers')\n  .should('have.property', 'x-custom-header', 'added by cy.intercept')"
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "The request modification cannot be verified by inspecting the browser's network\ntraffic (for example, in Chrome DevTools), since the browser logs network\ntraffic before Cypress can intercept it."
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "`cy.intercept()` cannot be debugged using\n"
          },
          {
            "type": "link",
            "title": null,
            "url": "/llm/markdown/api/commands/request.md",
            "children": [
              {
                "type": "text",
                "value": "`cy.request()`"
              }
            ]
          },
          {
            "type": "text",
            "value": "! Cypress only intercepts requests made\nby your front-end application."
          }
        ]
      },
      {
        "type": "heading",
        "depth": 4,
        "children": [
          {
            "type": "text",
            "value": "Controlling the response"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "The intercepted request passed to the route handler (hereafter referred to as\n`req`, though you can use any name) contains methods to dynamically control the\nresponse to a request:"
          }
        ]
      },
      {
        "type": "list",
        "ordered": false,
        "start": null,
        "spread": false,
        "children": [
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "`req.reply()` - stub out a response requiring no dependency on a real back-end"
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "`req.continue()` - modify or make assertions on the real response"
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "`req.destroy()` - destroy the request and respond with a network error"
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "`req.redirect()` - respond to the request with a redirect to a specified\nlocation"
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "`req.on()` - modify the response by attaching to events"
                  }
                ]
              }
            ]
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Stubbing out a response (`req.reply()`):"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "`req.reply()` takes a "
          },
          {
            "type": "linkReference",
            "children": [
              {
                "type": "text",
                "value": "`StaticResponse`"
              }
            ],
            "label": "staticresponse",
            "identifier": "staticresponse",
            "referenceType": "full"
          },
          {
            "type": "text",
            "value": " object as the first\nargument:"
          }
        ]
      },
      {
        "type": "code",
        "lang": "js",
        "meta": null,
        "value": "// stub out the response without interacting with a real back-end\ncy.intercept('POST', '/users', (req) => {\n  req.reply({\n    headers: {\n      Set-Cookie: 'newUserName=Peter Pan;'\n    },\n    statusCode: 201,\n    body: {\n      name: 'Peter Pan'\n    },\n    delay: 10, // milliseconds\n    throttleKbps: 1000, // to simulate a 3G connection\n    forceNetworkError: false // default\n  })\n})\n\n// stub out a response body using a fixture\ncy.intercept('GET', '/users', (req) => {\n  req.reply({\n    statusCode: 200, // default\n    fixture: 'users.json'\n  })\n})"
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "See "
          },
          {
            "type": "linkReference",
            "children": [
              {
                "type": "text",
                "value": "`StaticResponse` objects"
              }
            ],
            "label": "staticresponse",
            "identifier": "staticresponse",
            "referenceType": "full"
          },
          {
            "type": "text",
            "value": " below for more information."
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "The `reply` method also supports shorthand to avoid having to specify a\n`StaticResponse` object:"
          }
        ]
      },
      {
        "type": "code",
        "lang": "js",
        "meta": null,
        "value": "// equivalent to `req.reply({ body })`\nreq.reply(body)\n\n// equivalent to `req.reply({ body, headers })`\nreq.reply(body, headers)\n\n// equivalent to `req.reply({ statusCode, body, headers})`\nreq.reply(statusCode, body, headers)"
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Note: Calling `reply()` will end the request phase and stop the request from\npropagating to the next matching request handler in line. See "
          },
          {
            "type": "linkReference",
            "children": [
              {
                "type": "text",
                "value": "Interception\nLifecycle"
              }
            ],
            "label": "lifecycle",
            "identifier": "lifecycle",
            "referenceType": "full"
          },
          {
            "type": "text",
            "value": "."
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "See also\n"
          },
          {
            "type": "link",
            "title": null,
            "url": "#Providing-a-stub-response-with-reqreply",
            "children": [
              {
                "type": "text",
                "value": "Providing a stub response with `req.reply()`"
              }
            ]
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Modifying the real response (`continue`):"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "The `continue` method accepts a function which is passed an object representing\nthe real response being intercepted on its way back to the client (your\nfront-end application)."
          }
        ]
      },
      {
        "type": "code",
        "lang": "js",
        "meta": null,
        "value": "// pass the request through and make an assertion on\n// the real response\ncy.intercept('POST', '/users', (req) => {\n  req.continue((res) => {\n    expect(res.body).to.include('Peter Pan')\n  })\n})"
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "See also "
          },
          {
            "type": "linkReference",
            "children": [
              {
                "type": "text",
                "value": "Controlling the outbound request with `req.continue()`"
              }
            ],
            "label": "req-continue",
            "identifier": "req-continue",
            "referenceType": "full"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Responding with a network error (`destroy`):"
          }
        ]
      },
      {
        "type": "code",
        "lang": "js",
        "meta": null,
        "value": "// dynamically destroy the request and\n// respond with a network error\ncy.intercept('POST', '/users', (req) => {\n  if (mustDestroy(req)) {\n    req.destroy()\n  }\n\n  function mustDestroy(req) {\n    // code that determines whether to force a network error\n    // based on the contents of `req`\n  }\n})"
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Responding with a new location (`redirect`):"
          }
        ]
      },
      {
        "type": "code",
        "lang": "js",
        "meta": null,
        "value": "// respond to this request with a redirect to a new 'location'\ncy.intercept('GET', '/users', (req) => {\n  // statusCode defaults to `302`\n  req.redirect('/customers', 301)\n})"
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Responding by listening to events (`on`):"
          }
        ]
      },
      {
        "type": "code",
        "lang": "js",
        "meta": null,
        "value": "cy.intercept('GET', '/users', (req) => {\n  req.on('before:response', (res) => {\n    // do something when the `before:response` event is triggered\n  })\n})\ncy.intercept('POST', '/users', (req) => {\n  req.on('response', (res) => {\n    // do something when the `response` event is triggered\n  })\n})"
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "See example for\n"
          },
          {
            "type": "link",
            "title": null,
            "url": "#Throttle-or-delay-response-all-incoming-responses",
            "children": [
              {
                "type": "text",
                "value": "throttling a response"
              }
            ]
          },
          {
            "type": "text",
            "value": " See\nmore examples of "
          },
          {
            "type": "link",
            "title": null,
            "url": "#Request-events",
            "children": [
              {
                "type": "text",
                "value": "events"
              }
            ]
          }
        ]
      },
      {
        "type": "heading",
        "depth": 4,
        "children": [
          {
            "type": "text",
            "value": "Returning a Promise"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "If a Promise is returned from the route callback, it will be awaited before\ncontinuing with the request."
          }
        ]
      },
      {
        "type": "code",
        "lang": "js",
        "meta": null,
        "value": "cy.intercept('POST', '/users', (req) => {\n  // asynchronously fetch test data\n  return getAuthToken().then((token) => {\n    // ...and apply it to the outgoing request\n    req.headers['Authorization'] = `Basic ${token}`\n  })\n})\n\ncy.intercept('POST', '/users', (req) => {\n  req.continue((res) => {\n    // the response will not be sent to the browser until\n    // `waitForSomething()` resolves:\n    return waitForSomething()\n  })\n})"
      },
      {
        "type": "heading",
        "depth": 4,
        "children": [
          {
            "type": "text",
            "value": "Stubbing a response with a string"
          }
        ]
      },
      {
        "type": "code",
        "lang": "js",
        "meta": null,
        "value": "// requests to create a user will be fulfilled\n// with a body of 'success'\ncy.intercept('POST', '/users', 'success')\n// { body: 'success' }"
      },
      {
        "type": "heading",
        "depth": 2,
        "children": [
          {
            "type": "text",
            "value": "Intercepted requests"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "If a function is passed as the handler for a `cy.intercept()`, it will be called\nwith the first argument being an object that represents the intercepted HTTP\nrequest:"
          }
        ]
      },
      {
        "type": "code",
        "lang": "js",
        "meta": null,
        "value": "cy.intercept('/api', (req) => {\n  // `req` represents the intercepted HTTP request\n})"
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "From here, you can do several things with the intercepted request:"
          }
        ]
      },
      {
        "type": "list",
        "ordered": false,
        "start": null,
        "spread": false,
        "children": [
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "you can modify and assert on the request's properties (body, headers, URL,\nmethod...)"
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "the request can be sent to the real upstream server"
                  }
                ]
              },
              {
                "type": "list",
                "ordered": false,
                "start": null,
                "spread": false,
                "children": [
                  {
                    "type": "listItem",
                    "spread": false,
                    "checked": null,
                    "children": [
                      {
                        "type": "paragraph",
                        "children": [
                          {
                            "type": "text",
                            "value": "optionally, you can intercept the response from this"
                          }
                        ]
                      }
                    ]
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "a response can be provided to stub out the request"
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "listeners can be attached to various events on the request"
                  }
                ]
              }
            ]
          }
        ]
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Request object properties"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "The request object (`req`) has several properties from the HTTP request itself:"
          }
        ]
      },
      {
        "type": "code",
        "lang": "ts",
        "meta": null,
        "value": "{\n  /**\n   * The body of the request.\n   * If a JSON Content-Type was used and the body was valid JSON,\n   * this will be an object.\n   * If the body was binary content, this will be a buffer.\n   */\n  body: string | object | any\n  /**\n   * The headers of the request.\n   */\n  headers: { [key: string]: string }\n  /**\n   * Request HTTP method (GET, POST, ...).\n   */\n  method: string\n  /**\n   * Request URL.\n   */\n  url: string\n  /**\n   * URL query string as object.\n   */\n  query: Record<string, string|number>\n  /**\n   * The HTTP version used in the request. Read only.\n   */\n  httpVersion: string\n  /**\n   * The resource type of the request. Read only.\n   */\n  resourceType: 'document' | 'fetch' | 'xhr' | 'websocket' | 'stylesheet'\n              | 'script' | 'image' | 'font' | 'cspviolationreport' | 'ping'\n              | 'manifest' | 'other'\n}"
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "`req` also has some optional properties which can be set to control\nCypress-specific behavior:"
          }
        ]
      },
      {
        "type": "code",
        "lang": "ts",
        "meta": null,
        "value": "{\n  /**\n   * If provided, the number of milliseconds before an upstream\n   * response to this request will time out and cause an error.\n   * By default, `responseTimeout` from config is used.\n   */\n  responseTimeout?: number\n  /**\n   * Set if redirects should be followed when this request is made.\n   * By default, requests will not follow redirects before\n   * yielding the response (the 3xx redirect is yielded).\n   */\n  followRedirect?: boolean\n  /**\n   * If set, `cy.wait` can be used to await the request/response\n   * cycle to complete for this request via `cy.wait('@alias')`.\n   */\n  alias?: string\n}"
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Any modifications to the properties of `req` will be persisted to other request\nhandlers, and finally merged into the actual outbound HTTP request."
          }
        ]
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Controlling the outbound request with req.continue()"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Calling `req.continue()` without any argument will cause the request to be sent\noutgoing, and the response will be returned to the browser after any other\nlisteners have been called. For example, the following code modifies a `POST`\nrequest and then sends it to the upstream server:"
          }
        ]
      },
      {
        "type": "code",
        "lang": "js",
        "meta": null,
        "value": "cy.intercept('POST', '/submitStory', (req) => {\n  req.body.storyName = 'some name'\n  // send the modified request and skip any other\n  // matching request handlers\n  req.continue()\n})"
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "If a function is passed to `req.continue()`, the request will be sent to the\nreal upstream server, and the callback will be called with the response once the\nresponse is fully received from the server. See "
          },
          {
            "type": "linkReference",
            "children": [
              {
                "type": "text",
                "value": "\"Intercepted responses\""
              }
            ],
            "label": "res",
            "identifier": "res",
            "referenceType": "full"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Note: calling `req.continue()` will stop the request from propagating to the\nnext matching request handler in line. See "
          },
          {
            "type": "linkReference",
            "children": [
              {
                "type": "text",
                "value": "\"Interception lifecycle\""
              }
            ],
            "label": "lifecycle",
            "identifier": "lifecycle",
            "referenceType": "full"
          },
          {
            "type": "text",
            "value": "\nfor more information."
          }
        ]
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Providing a stub response with req.reply()"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "The `req.reply()` function can be used to send a stub response for an\nintercepted request. By passing a string, object, or\n"
          },
          {
            "type": "linkReference",
            "children": [
              {
                "type": "text",
                "value": "`StaticResponse`"
              }
            ],
            "label": "staticresponse",
            "identifier": "staticresponse",
            "referenceType": "full"
          },
          {
            "type": "text",
            "value": " to `req.reply()`, the request can be\npreventing from reaching the destination server."
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "For example, the following code stubs out a JSON response from a request\ninterceptor:"
          }
        ]
      },
      {
        "type": "code",
        "lang": "js",
        "meta": null,
        "value": "cy.intercept('/billing', (req) => {\n  // dynamically get billing plan name at request-time\n  const planName = getPlanName()\n  // this object will automatically be JSON.stringified and\n  // sent as the response\n  req.reply({ plan: planName })\n})"
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Instead of passing a plain object or string to `req.reply()`, you can also pass\na "
          },
          {
            "type": "linkReference",
            "children": [
              {
                "type": "text",
                "value": "`StaticResponse`"
              }
            ],
            "label": "staticresponse",
            "identifier": "staticresponse",
            "referenceType": "full"
          },
          {
            "type": "text",
            "value": " object. With a\n"
          },
          {
            "type": "linkReference",
            "children": [
              {
                "type": "text",
                "value": "`StaticResponse`"
              }
            ],
            "label": "staticresponse",
            "identifier": "staticresponse",
            "referenceType": "full"
          },
          {
            "type": "text",
            "value": ", you can force a network error,\ndelay/throttle the response, send a fixture, and more."
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "For example, the following code serves a dynamically chosen fixture with a delay\nof 500ms:"
          }
        ]
      },
      {
        "type": "code",
        "lang": "js",
        "meta": null,
        "value": "cy.intercept('/api/users/*', async (req) => {\n  // asynchronously retrieve fixture filename at request-time\n  const fixtureFilename = await getFixtureFilenameForUrl(req.url)\n  req.reply({\n    fixture: fixtureFilename,\n    delay: 500,\n  })\n})"
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "See the "
          },
          {
            "type": "linkReference",
            "children": [
              {
                "type": "text",
                "value": "`StaticResponse` documentation"
              }
            ],
            "label": "staticresponse",
            "identifier": "staticresponse",
            "referenceType": "full"
          },
          {
            "type": "text",
            "value": " for more information on\nstubbing responses in this manner."
          }
        ]
      },
      {
        "type": "heading",
        "depth": 4,
        "children": [
          {
            "type": "text",
            "value": "req.reply() shorthand"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "`req.reply()` also supports shorthand, similar to "
          },
          {
            "type": "linkReference",
            "children": [
              {
                "type": "text",
                "value": "`res.send()`"
              }
            ],
            "label": "res-send",
            "identifier": "res-send",
            "referenceType": "full"
          },
          {
            "type": "text",
            "value": ", to\navoid having to specify a `StaticResponse` object:"
          }
        ]
      },
      {
        "type": "code",
        "lang": "js",
        "meta": null,
        "value": "// equivalent to `req.reply({ body })`\nreq.reply(body)\n\n// equivalent to `req.reply({ body, headers })`\nreq.reply(body, headers)\n\n// equivalent to `req.reply({ statusCode, body, headers})`\nreq.reply(statusCode, body, headers)"
      },
      {
        "type": "heading",
        "depth": 4,
        "children": [
          {
            "type": "text",
            "value": "Convenience functions"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "There are also two convenience functions available on `req`:"
          }
        ]
      },
      {
        "type": "code",
        "lang": "ts",
        "meta": null,
        "value": "{\n  /**\n   * Destroy the request and respond with a network error.\n   */\n  destroy(): void\n  /**\n   * Respond to this request with a redirect to a new 'location'.\n   * @param statusCode HTTP status code to redirect with. Default: 302\n   */\n  redirect(location: string, statusCode?: number): void\n}"
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "See examples in the "
          },
          {
            "type": "link",
            "title": null,
            "url": "#Controlling-the-response",
            "children": [
              {
                "type": "text",
                "value": "Controlling the response"
              }
            ]
          },
          {
            "type": "text",
            "value": "\nsection"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Note: calling `req.reply()` will end the request phase and stop the request from\npropagating to the next matching request handler in line. See "
          },
          {
            "type": "linkReference",
            "children": [
              {
                "type": "text",
                "value": "\"Interception\nlifecycle\""
              }
            ],
            "label": "lifecycle",
            "identifier": "lifecycle",
            "referenceType": "full"
          },
          {
            "type": "text",
            "value": " for more information."
          }
        ]
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Request events"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "For advanced use, several events are available on `req`, that represent\ndifferent stages of the "
          },
          {
            "type": "linkReference",
            "children": [
              {
                "type": "text",
                "value": "Interception lifecycle"
              }
            ],
            "label": "lifecycle",
            "identifier": "lifecycle",
            "referenceType": "full"
          },
          {
            "type": "text",
            "value": "."
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "By calling `req.on`, you can subscribe to different events:"
          }
        ]
      },
      {
        "type": "code",
        "lang": "js",
        "meta": null,
        "value": "cy.intercept('/shop', (req) => {\n  req.on('before:response', (res) => {\n    /**\n     * Emitted before `response` and before any `req.continue`\n     * handlers. Modifications to `res` will be applied to the\n     * incoming response. If a promise is returned, it will be\n     * awaited before processing other event handlers.\n     */\n  })\n\n  req.on('response', (res) => {\n    /**\n     * Emitted after `before:response` and after any\n     * `req.continue` handlers - before the response is sent\n     * to the browser. Modifications to `res` will be applied\n     * to the incoming response. If a promise is returned, it\n     * will be awaited before processing other event handlers.\n     */\n  })\n\n  req.on('after:response', (res) => {\n    /**\n     * Emitted once the response to a request has finished\n     * sending to the browser. Modifications to `res` have no\n     * impact. If a promise is returned, it will be awaited\n     * before processing other event handlers.\n     */\n  })\n})"
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "See "
          },
          {
            "type": "linkReference",
            "children": [
              {
                "type": "text",
                "value": "\"Intercepted responses\""
              }
            ],
            "label": "res",
            "identifier": "res",
            "referenceType": "full"
          },
          {
            "type": "text",
            "value": " for more details on the `res` object yielded\nby `before:response` and `response`. See "
          },
          {
            "type": "linkReference",
            "children": [
              {
                "type": "text",
                "value": "\"Interception lifecycle\""
              }
            ],
            "label": "lifecycle",
            "identifier": "lifecycle",
            "referenceType": "full"
          },
          {
            "type": "text",
            "value": "\nfor more details on request ordering."
          }
        ]
      },
      {
        "type": "heading",
        "depth": 2,
        "children": [
          {
            "type": "text",
            "value": "Intercepted responses"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "The response can be intercepted in two ways:"
          }
        ]
      },
      {
        "type": "list",
        "ordered": false,
        "start": null,
        "spread": false,
        "children": [
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "by passing a callback to "
                  },
                  {
                    "type": "linkReference",
                    "children": [
                      {
                        "type": "text",
                        "value": "`req.continue()`"
                      }
                    ],
                    "label": "req-continue",
                    "identifier": "req-continue",
                    "referenceType": "full"
                  },
                  {
                    "type": "text",
                    "value": " within a request\nhandler"
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "by listening for the `before:response` or `response` request events (see\n"
                  },
                  {
                    "type": "link",
                    "title": null,
                    "url": "#Request-events",
                    "children": [
                      {
                        "type": "text",
                        "value": "\"Request events\""
                      }
                    ]
                  },
                  {
                    "type": "text",
                    "value": ")"
                  }
                ]
              }
            ]
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "The response object, `res`, will be passed as the first argument to the handler\nfunction:"
          }
        ]
      },
      {
        "type": "code",
        "lang": "js",
        "meta": null,
        "value": "cy.intercept('/url', (req) => {\n  req.on('before:response', (res) => {\n    // this will be called before any `req.continue` or\n    // `response` handlers\n  })\n\n  req.continue((res) => {\n    // this will be called after all `before:response`\n    // handlers and before any `response` handlers\n    // by calling `req.continue`, we signal that this\n    // request handler will be the last one, and that\n    // the request should be sent outgoing at this point.\n    // for that reason, there can only be one\n    // `req.continue` handler per request.\n  })\n\n  req.on('response', (res) => {\n    // this will be called after all `before:response`\n    // handlers and after the `req.continue` handler\n    // but before the response is sent to the browser\n  })\n})"
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Response object properties"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "The response object (`res`) yielded to response handlers has several properties\nfrom the HTTP response itself. All of the following properties on `res` can be\nmodified:"
          }
        ]
      },
      {
        "type": "table",
        "align": [
          null,
          null
        ],
        "children": [
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Property"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Description"
                  }
                ]
              }
            ]
          },
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "body"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "response body (`object`, `string`, `ArrayBuffer`)"
                  }
                ]
              }
            ]
          },
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "headers"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "response headers (`object`)"
                  }
                ]
              }
            ]
          },
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "statusCode"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "response status code (`number`)"
                  }
                ]
              }
            ]
          },
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "statusMessage"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "response status message (`string`)"
                  }
                ]
              }
            ]
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Note about `body`: If the response header contains\n`Content-Type: application/json` and the body contains valid JSON, this will be\nan `object`. And if the body contains binary content, this will be a buffer."
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "`res` also has some optional properties which can be set to control\nCypress-specific behavior:"
          }
        ]
      },
      {
        "type": "table",
        "align": [
          null,
          null
        ],
        "children": [
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Property"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Description"
                  }
                ]
              }
            ]
          },
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "throttleKbps"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Maximum data transfer rate of the response (kilobits/second)"
                  }
                ]
              }
            ]
          },
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "delay"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Minimum network latency or delay to add to the response time (milliseconds)"
                  }
                ]
              }
            ]
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Any modifications to the properties of `res` will be persisted to other response\nhandlers, and finally merged into the actual incoming HTTP response."
          }
        ]
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Ending the response with res.send()"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "To end the response phase of the request, call `res.send()`. Optionally, you can\npass a "
          },
          {
            "type": "linkReference",
            "children": [
              {
                "type": "text",
                "value": "`StaticResponse`"
              }
            ],
            "label": "staticresponse",
            "identifier": "staticresponse",
            "referenceType": "full"
          },
          {
            "type": "text",
            "value": " to `res.send()`, to be merged with the\nactual response."
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "When `res.send()` is called, the response phase will end immediately and no\nother response handlers will be called for the current request. Here is an\nexample of how `res.send()` could be used:"
          }
        ]
      },
      {
        "type": "code",
        "lang": "js",
        "meta": null,
        "value": "cy.intercept('/notification', (req) => {\n  req.continue((res) => {\n    if (res.body.status === 'failed') {\n      // sends a fixture body instead of the existing 'res.body'\n      res.send({ fixture: 'success.json' })\n    }\n  })\n})"
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "See the "
          },
          {
            "type": "linkReference",
            "children": [
              {
                "type": "text",
                "value": "`StaticResponse` documentation"
              }
            ],
            "label": "staticresponse",
            "identifier": "staticresponse",
            "referenceType": "full"
          },
          {
            "type": "text",
            "value": " for more information on\nthe format."
          }
        ]
      },
      {
        "type": "heading",
        "depth": 4,
        "children": [
          {
            "type": "text",
            "value": "res.send() shorthand"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "`res.send()` also supports shorthand, similar to "
          },
          {
            "type": "linkReference",
            "children": [
              {
                "type": "text",
                "value": "`req.reply()`"
              }
            ],
            "label": "req-reply",
            "identifier": "req-reply",
            "referenceType": "full"
          },
          {
            "type": "text",
            "value": ", to\navoid having to specify a `StaticResponse` object:"
          }
        ]
      },
      {
        "type": "code",
        "lang": "js",
        "meta": null,
        "value": "// equivalent to `res.send({ body })`\nres.send(body)\n\n// equivalent to `res.send({ body, headers })`\nres.send(body, headers)\n\n// equivalent to `res.send({ statusCode, body, headers})`\nres.send(statusCode, body, headers)"
      },
      {
        "type": "heading",
        "depth": 4,
        "children": [
          {
            "type": "text",
            "value": "Convenience functions"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "There are also two convenience functions available on `res`:"
          }
        ]
      },
      {
        "type": "code",
        "lang": "ts",
        "meta": null,
        "value": "{\n  /**\n   * Wait for 'delay' milliseconds before sending the\n   * response to the client.\n   */\n  setDelay: (delay: number) => IncomingHttpResponse\n  /**\n   * Serve the response at 'throttleKbps' kilobytes per second.\n   */\n  setThrottle: (throttleKbps: number) => IncomingHttpResponse\n}"
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Note: calling `res.send()` will end the response phase and stop the response\nfrom propagating to the next matching response handler in line. See\n"
          },
          {
            "type": "linkReference",
            "children": [
              {
                "type": "text",
                "value": "\"Interception lifecycle\""
              }
            ],
            "label": "lifecycle",
            "identifier": "lifecycle",
            "referenceType": "full"
          },
          {
            "type": "text",
            "value": " for more information."
          }
        ]
      },
      {
        "type": "heading",
        "depth": 2,
        "children": [
          {
            "type": "text",
            "value": "StaticResponse objects"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "A `StaticResponse` represents a\n"
          },
          {
            "type": "link",
            "title": null,
            "url": "#Stubbing-a-response",
            "children": [
              {
                "type": "text",
                "value": "statically defined response (stub)"
              }
            ]
          },
          {
            "type": "text",
            "value": "."
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "The following properties are available on `StaticResponse`."
          }
        ]
      },
      {
        "type": "table",
        "align": [
          null,
          null
        ],
        "children": [
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Option"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Description"
                  }
                ]
              }
            ]
          },
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "statusCode"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "HTTP response status code"
                  }
                ]
              }
            ]
          },
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "headers"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "HTTP response headers"
                  }
                ]
              }
            ]
          },
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "body"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Serve a static response body (`object`, `string`, `ArrayBuffer`) (when `fixture` is omitted)."
                  }
                ]
              }
            ]
          },
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "fixture"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Serve a fixture as the HTTP response body (allowed when `body` is omitted). Read the contents with an encoding other than the "
                  },
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/api/commands/fixture.md#Encoding",
                    "children": [
                      {
                        "type": "text",
                        "value": "default for the file type"
                      }
                    ]
                  },
                  {
                    "type": "text",
                    "value": ", pass the fixture like `path,encoding`."
                  }
                ]
              }
            ]
          },
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "forceNetworkError"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Force an error by destroying the browser connection"
                  }
                ]
              }
            ]
          },
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "delay"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Minimum network latency or delay to add to the response time (milliseconds)"
                  }
                ]
              }
            ]
          },
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "throttleKbps"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Maximum data transfer rate of the response (kilobits/second)"
                  }
                ]
              }
            ]
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Note: All properties are optional."
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "You can supply a `StaticResponse` to Cypress in 3 ways:"
          }
        ]
      },
      {
        "type": "list",
        "ordered": false,
        "start": null,
        "spread": false,
        "children": [
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "To `cy.intercept()` as\n"
                  },
                  {
                    "type": "link",
                    "title": null,
                    "url": "#staticResponse-StaticResponse",
                    "children": [
                      {
                        "type": "text",
                        "value": "`an argument`"
                      }
                    ]
                  },
                  {
                    "type": "text",
                    "value": ", to stub a\nresponse to a route: `cy.intercept('/url', staticResponse)`"
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "To "
                  },
                  {
                    "type": "linkReference",
                    "children": [
                      {
                        "type": "text",
                        "value": "`req.reply()`"
                      }
                    ],
                    "label": "req-reply",
                    "identifier": "req-reply",
                    "referenceType": "full"
                  },
                  {
                    "type": "text",
                    "value": ", to stub a response from a request handler:\n`req.reply(staticResponse)`"
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "To "
                  },
                  {
                    "type": "linkReference",
                    "children": [
                      {
                        "type": "text",
                        "value": "`res.send()`"
                      }
                    ],
                    "label": "res-send",
                    "identifier": "res-send",
                    "referenceType": "full"
                  },
                  {
                    "type": "text",
                    "value": ", to stub a response from a response handler:\n`res.send(staticResponse)`"
                  }
                ]
              }
            ]
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "See\n"
          },
          {
            "type": "link",
            "title": null,
            "url": "#With-a-StaticResponse-object",
            "children": [
              {
                "type": "text",
                "value": "\"Stubbing a response with a `StaticResponse` object\""
              }
            ]
          },
          {
            "type": "text",
            "value": "\nfor examples of stubbing with `cy.intercept()`."
          }
        ]
      },
      {
        "type": "heading",
        "depth": 2,
        "children": [
          {
            "type": "text",
            "value": "Interception lifecycle"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "The lifecycle of a `cy.intercept()` interception begins when an HTTP request is\nsent from your app that matches one or more registered `cy.intercept()` routes.\nFrom there, each interception has two phases: request and response."
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "`cy.intercept()` routes are matched in reverse order of definition, except for\nroutes which are defined with `{ middleware: true }`, which always run first.\nThis allows you to override existing `cy.intercept()` declarations by defining\nan overlapping `cy.intercept()`:"
          }
        ]
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Request phase"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "The following steps are used to handle the request phase."
          }
        ]
      },
      {
        "type": "list",
        "ordered": true,
        "start": 1,
        "spread": false,
        "children": [
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "Start with the first matching route according to the above algorithm\n(middleware first, followed by handlers in reverse order)."
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "Was a handler (body, "
                  },
                  {
                    "type": "linkReference",
                    "children": [
                      {
                        "type": "text",
                        "value": "`StaticResponse`"
                      }
                    ],
                    "label": "staticresponse",
                    "identifier": "staticresponse",
                    "referenceType": "full"
                  },
                  {
                    "type": "text",
                    "value": ", or function)\nsupplied to `cy.intercept()`? If not, continue to step 7."
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "If the handler was a body or "
                  },
                  {
                    "type": "linkReference",
                    "children": [
                      {
                        "type": "text",
                        "value": "`StaticResponse`"
                      }
                    ],
                    "label": "staticresponse",
                    "identifier": "staticresponse",
                    "referenceType": "full"
                  },
                  {
                    "type": "text",
                    "value": ", immediately\nend the request with that response."
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "If the handler was a function, call the function with `req`, the incoming\nrequest, as the first argument. See "
                  },
                  {
                    "type": "linkReference",
                    "children": [
                      {
                        "type": "text",
                        "value": "\"Intercepted requests\""
                      }
                    ],
                    "label": "req",
                    "identifier": "req",
                    "referenceType": "full"
                  },
                  {
                    "type": "text",
                    "value": " for more\ninformation on the `req` object."
                  }
                ]
              },
              {
                "type": "list",
                "ordered": false,
                "start": null,
                "spread": false,
                "children": [
                  {
                    "type": "listItem",
                    "spread": false,
                    "checked": null,
                    "children": [
                      {
                        "type": "paragraph",
                        "children": [
                          {
                            "type": "text",
                            "value": "If "
                          },
                          {
                            "type": "linkReference",
                            "children": [
                              {
                                "type": "text",
                                "value": "`req.reply()`"
                              }
                            ],
                            "label": "req-reply",
                            "identifier": "req-reply",
                            "referenceType": "full"
                          },
                          {
                            "type": "text",
                            "value": " is called, immediately end the request phase\nwith the provided response. See\n"
                          },
                          {
                            "type": "link",
                            "title": null,
                            "url": "#Providing-a-stub-response-with-reqreply",
                            "children": [
                              {
                                "type": "text",
                                "value": "\"Providing a stub response with `req.reply()`\""
                              }
                            ]
                          },
                          {
                            "type": "text",
                            "value": "."
                          }
                        ]
                      }
                    ]
                  },
                  {
                    "type": "listItem",
                    "spread": false,
                    "checked": null,
                    "children": [
                      {
                        "type": "paragraph",
                        "children": [
                          {
                            "type": "text",
                            "value": "If "
                          },
                          {
                            "type": "linkReference",
                            "children": [
                              {
                                "type": "text",
                                "value": "`req.continue()`"
                              }
                            ],
                            "label": "req-continue",
                            "identifier": "req-continue",
                            "referenceType": "full"
                          },
                          {
                            "type": "text",
                            "value": " is called, immediately end the request\nphase, and send the request to the destination server. If a callback is\nprovided to "
                          },
                          {
                            "type": "linkReference",
                            "children": [
                              {
                                "type": "text",
                                "value": "`req.continue()`"
                              }
                            ],
                            "label": "req-continue",
                            "identifier": "req-continue",
                            "referenceType": "full"
                          },
                          {
                            "type": "text",
                            "value": ", it will be called during the\n"
                          },
                          {
                            "type": "link",
                            "title": null,
                            "url": "#Response-phase",
                            "children": [
                              {
                                "type": "text",
                                "value": "response phase"
                              }
                            ]
                          }
                        ]
                      }
                    ]
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "If the handler returned a Promise, wait for the Promise to resolve."
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "Merge any modifications to the request object with the real request."
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "If there is another matching `cy.intercept()`, return to step 2 and continue\nfollowing steps with that route."
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "Send the request outgoing to the destination server and end the request\nphase. The "
                  },
                  {
                    "type": "link",
                    "title": null,
                    "url": "#Response-phase",
                    "children": [
                      {
                        "type": "text",
                        "value": "response phase"
                      }
                    ]
                  },
                  {
                    "type": "text",
                    "value": " will begin once a response is\nreceived."
                  }
                ]
              }
            ]
          }
        ]
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Response phase"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Once the HTTP response is received from the upstream server, the following steps\nare applied:"
          }
        ]
      },
      {
        "type": "list",
        "ordered": true,
        "start": 1,
        "spread": false,
        "children": [
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "Get a list of registered `before:response` event listeners."
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "For each `before:response` listener (if any), call it with the "
                  },
                  {
                    "type": "linkReference",
                    "children": [
                      {
                        "type": "text",
                        "value": "`res`"
                      }
                    ],
                    "label": "res",
                    "identifier": "res",
                    "referenceType": "full"
                  },
                  {
                    "type": "text",
                    "value": "\nobject."
                  }
                ]
              },
              {
                "type": "list",
                "ordered": false,
                "start": null,
                "spread": false,
                "children": [
                  {
                    "type": "listItem",
                    "spread": false,
                    "checked": null,
                    "children": [
                      {
                        "type": "paragraph",
                        "children": [
                          {
                            "type": "text",
                            "value": "If "
                          },
                          {
                            "type": "linkReference",
                            "children": [
                              {
                                "type": "text",
                                "value": "`res.send()`"
                              }
                            ],
                            "label": "res-send",
                            "identifier": "res-send",
                            "referenceType": "full"
                          },
                          {
                            "type": "text",
                            "value": " is called, end the response phase and merge any\npassed arguments with the response."
                          }
                        ]
                      }
                    ]
                  },
                  {
                    "type": "listItem",
                    "spread": false,
                    "checked": null,
                    "children": [
                      {
                        "type": "paragraph",
                        "children": [
                          {
                            "type": "text",
                            "value": "If a Promise is returned, await it. Merge any modified response properties\nwith the real response."
                          }
                        ]
                      }
                    ]
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "If a `req.continue()` with callback is declared for this route, call the\ncallback with the "
                  },
                  {
                    "type": "linkReference",
                    "children": [
                      {
                        "type": "text",
                        "value": "`res`"
                      }
                    ],
                    "label": "res",
                    "identifier": "res",
                    "referenceType": "full"
                  },
                  {
                    "type": "text",
                    "value": " object."
                  }
                ]
              },
              {
                "type": "list",
                "ordered": false,
                "start": null,
                "spread": false,
                "children": [
                  {
                    "type": "listItem",
                    "spread": false,
                    "checked": null,
                    "children": [
                      {
                        "type": "paragraph",
                        "children": [
                          {
                            "type": "text",
                            "value": "If "
                          },
                          {
                            "type": "linkReference",
                            "children": [
                              {
                                "type": "text",
                                "value": "`res.send()`"
                              }
                            ],
                            "label": "res-send",
                            "identifier": "res-send",
                            "referenceType": "full"
                          },
                          {
                            "type": "text",
                            "value": " is called, end the response phase and merge any\npassed arguments with the response."
                          }
                        ]
                      }
                    ]
                  },
                  {
                    "type": "listItem",
                    "spread": false,
                    "checked": null,
                    "children": [
                      {
                        "type": "paragraph",
                        "children": [
                          {
                            "type": "text",
                            "value": "If a Promise is returned, await it. Merge any modified response properties\nwith the real response."
                          }
                        ]
                      }
                    ]
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "Get a list of registered `response` event listeners."
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "For each `response` listener (if any), call it with the "
                  },
                  {
                    "type": "linkReference",
                    "children": [
                      {
                        "type": "text",
                        "value": "`res`"
                      }
                    ],
                    "label": "res",
                    "identifier": "res",
                    "referenceType": "full"
                  },
                  {
                    "type": "text",
                    "value": " object."
                  }
                ]
              },
              {
                "type": "list",
                "ordered": false,
                "start": null,
                "spread": false,
                "children": [
                  {
                    "type": "listItem",
                    "spread": false,
                    "checked": null,
                    "children": [
                      {
                        "type": "paragraph",
                        "children": [
                          {
                            "type": "text",
                            "value": "If "
                          },
                          {
                            "type": "linkReference",
                            "children": [
                              {
                                "type": "text",
                                "value": "`res.send()`"
                              }
                            ],
                            "label": "res-send",
                            "identifier": "res-send",
                            "referenceType": "full"
                          },
                          {
                            "type": "text",
                            "value": " is called, end the response phase and merge any\npassed arguments with the response."
                          }
                        ]
                      }
                    ]
                  },
                  {
                    "type": "listItem",
                    "spread": false,
                    "checked": null,
                    "children": [
                      {
                        "type": "paragraph",
                        "children": [
                          {
                            "type": "text",
                            "value": "If a Promise is returned, await it. Merge any modified response properties\nwith the real response."
                          }
                        ]
                      }
                    ]
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "Send the response to the browser."
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "Once the response is complete, get a list of registered `after:response`\nevent listeners."
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "For each `after:response` listener (if any), call it with the "
                  },
                  {
                    "type": "linkReference",
                    "children": [
                      {
                        "type": "text",
                        "value": "`res`"
                      }
                    ],
                    "label": "res",
                    "identifier": "res",
                    "referenceType": "full"
                  },
                  {
                    "type": "text",
                    "value": "\nobject (minus `res.send`)"
                  }
                ]
              },
              {
                "type": "list",
                "ordered": false,
                "start": null,
                "spread": false,
                "children": [
                  {
                    "type": "listItem",
                    "spread": false,
                    "checked": null,
                    "children": [
                      {
                        "type": "paragraph",
                        "children": [
                          {
                            "type": "text",
                            "value": "If a Promise is returned, await it."
                          }
                        ]
                      }
                    ]
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "End the response phase."
                  }
                ]
              }
            ]
          }
        ]
      },
      {
        "type": "heading",
        "depth": 2,
        "children": [
          {
            "type": "text",
            "value": "Glob Pattern Matching URLs"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "When "
          },
          {
            "type": "linkReference",
            "children": [
              {
                "type": "text",
                "value": "matching a URL"
              }
            ],
            "label": "match-url",
            "identifier": "match-url",
            "referenceType": "full"
          },
          {
            "type": "text",
            "value": ", providing an exact URL to match can be too\nrestrictive. For example, what if you wanted to run your tests on a different\nhost?"
          }
        ]
      },
      {
        "type": "code",
        "lang": "js",
        "meta": null,
        "value": "// match any request that exactly matches the URL\ncy.intercept('https://prod.cypress.io/users')\n// matches this: https://prod.cypress.io/users\n// ...but not this: https://staging.cypress.io/users\n// ...or this: http://localhost/users"
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Glob pattern matching provides the necessary flexibility:"
          }
        ]
      },
      {
        "type": "code",
        "lang": "js",
        "meta": null,
        "value": "cy.intercept('/users')\n// matches all of these:\n//   https://prod.cypress.io/users\n//   https://staging.cypress.io/users\n//   http://localhost/users\n\ncy.intercept('/users?_limit=+(3|5)')\n// matches all of these:\n//   https://prod.cypress.io/users?_limit=3\n//   http://localhost/users?_limit=5"
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Cypress.minimatch"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Under the hood, `cy.intercept` uses the "
          },
          {
            "type": "link",
            "title": null,
            "url": "/llm/markdown/api/utilities/minimatch.md",
            "children": [
              {
                "type": "text",
                "value": "minimatch"
              }
            ]
          },
          {
            "type": "text",
            "value": "\nlibrary with the `{ matchBase: true }` option applied for glob matching and\nprovides access to it via the `Cypress` global. This enables you to test your\npattern in your spec or in the Cypress browser console."
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "You can invoke the `Cypress.minimatch` with just two arguments - the URL\n(`string`) and the pattern (`string`), respectively - and if it yields `true`,\nthen you have a match!"
          }
        ]
      },
      {
        "type": "code",
        "lang": "javascript",
        "meta": null,
        "value": "expect(\n  Cypress.minimatch('http://localhost/users?_limit=3', '**/users?_limit=+(3|5)')\n).to.be.true\nexpect(\n  Cypress.minimatch('http://localhost/users?_limit=5', '/users?_limit=+(3|5)', {\n    matchBase: true,\n  })\n).to.be.true\nexpect(\n  Cypress.minimatch('http://localhost/users?_limit=7', '**/users?_limit=+(3|5)')\n).to.be.false"
      },
      {
        "type": "heading",
        "depth": 4,
        "children": [
          {
            "type": "text",
            "value": "minimatch options"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "You can also pass in options (`object`) as the third argument, one of which is\n`debug` which if set to `true`, will yield verbose output that could help you\nunderstand why your pattern isn't working as you expect:"
          }
        ]
      },
      {
        "type": "code",
        "lang": "js",
        "meta": null,
        "value": "Cypress.minimatch('http://localhost/users?_limit=3', '**/users?_limit=+(3|5)', {\n  debug: true,\n})\n// true (plus debug messages)"
      },
      {
        "type": "heading",
        "depth": 2,
        "children": [
          {
            "type": "text",
            "value": "cy.intercept() and request caching"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "`cy.intercept()` intercepts requests at the network layer. This can cause\nconfusion when trying to intercept a request that has already been cached by the\nbrowser. If a request is served from the browser cache, it will never hit the\nnetwork layer, and `cy.intercept()` will never fire."
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "To see if this is affecting your app, check the Developer Tools. In the\nfollowing example, all of the requests circled in red have been served from\ncache, and will not send an HTTP request. Thus, they cannot be intercepted by\n`cy.intercept()`:"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "If you would like to intercept resources that normally send cache headers, here\nare some workarounds:"
          }
        ]
      },
      {
        "type": "list",
        "ordered": false,
        "start": null,
        "spread": false,
        "children": [
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "Turn off cache headers on your development server when in testing mode."
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "Disable caching on responses by adding a top-level `cy.intercept()` that\nremoves cache headers from desired requests. For example:"
                  }
                ]
              },
              {
                "type": "code",
                "lang": "ts",
                "meta": null,
                "value": "beforeEach(() => {\n  cy.intercept(\n    'https://api.example.com/**/*',\n    { middleware: true },\n    (req) => {\n      req.on('before:response', (res) => {\n        // force all API responses to not be cached\n        res.headers['cache-control'] = 'no-store'\n      })\n    }\n  )\n})"
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "Chromium-family browsers only: Use `remote:debugger:protocol` to disable cache\nentirely. For more information, see\n"
                  },
                  {
                    "type": "link",
                    "title": null,
                    "url": "https://github.com/cypress-io/cypress/issues/14459#issuecomment-768616195",
                    "children": [
                      {
                        "type": "text",
                        "value": "this comment on issue #14459"
                      }
                    ]
                  }
                ]
              }
            ]
          }
        ]
      },
      {
        "type": "heading",
        "depth": 2,
        "children": [
          {
            "type": "text",
            "value": "Command Log"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Routes Instrument Panel"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "When you create `cy.intercept()` rules, Cypress will display a new Instrument called Routes."
          }
        ]
      },
      {
        "type": "code",
        "lang": "javascript",
        "meta": null,
        "value": "cy.intercept('/accounts*').as('accountsGet')\ncy.intercept('/company', { companyId: 1 }).as('companyGet')\ncy.intercept('/teams*', [{ teamId: 2 }]).as('teamsGet')"
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "It will list the routing table in the\nInstrument Panel, including the `method`, `RouteMatcher`, if the route is\nstubbed, any alias, and number of matched requests:"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "When HTTP requests are made, Cypress will log them in the Command Log and\nindicate whether they matched a `cy.intercept()` by the presence of a yellow\nbadge on the right hand side:"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "The circular indicator is filled if the request went to the destination server,\nbut unfilled if the request was stubbed with a response."
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Clicking on a request that matched a `cy.intercept()` will print additional\ninformation about the request and response to the console:"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "link",
            "title": null,
            "url": "/llm/markdown/app/guides/network-requests.md#Command-Log",
            "children": [
              {
                "type": "text",
                "value": "Read more about request logging in Cypress."
              }
            ]
          }
        ]
      },
      {
        "type": "heading",
        "depth": 2,
        "children": [
          {
            "type": "text",
            "value": "History"
          }
        ]
      },
      {
        "type": "table",
        "align": [
          null,
          null
        ],
        "children": [
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Version"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Changes"
                  }
                ]
              }
            ]
          },
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/app/references/changelog.md#14-0-0",
                    "children": [
                      {
                        "type": "text",
                        "value": "14.0.0"
                      }
                    ]
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Deprecated `resourceType` property"
                  }
                ]
              }
            ]
          },
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/app/references/changelog.md#12-2-0",
                    "children": [
                      {
                        "type": "text",
                        "value": "12.2.0"
                      }
                    ]
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Added `resourceType` property to `req` and `RouteMatcher`."
                  }
                ]
              }
            ]
          },
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/app/references/changelog.md#7-0-0",
                    "children": [
                      {
                        "type": "text",
                        "value": "7.6.0"
                      }
                    ]
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Added `query` option to `req` (The incoming request object yielded to request handler functions)."
                  }
                ]
              }
            ]
          },
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/app/references/changelog.md#7-0-0",
                    "children": [
                      {
                        "type": "text",
                        "value": "7.0.0"
                      }
                    ]
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "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()`."
                  }
                ]
              }
            ]
          },
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/app/references/changelog.md#6-4-0",
                    "children": [
                      {
                        "type": "text",
                        "value": "6.4.0"
                      }
                    ]
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Renamed `delayMs` property to `delay` (backwards-compatible)."
                  }
                ]
              }
            ]
          },
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/app/references/changelog.md#6-2-0",
                    "children": [
                      {
                        "type": "text",
                        "value": "6.2.0"
                      }
                    ]
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Added `matchUrlAgainstPath` option to `RouteMatcher`."
                  }
                ]
              }
            ]
          },
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/app/references/changelog.md#6-0-0",
                    "children": [
                      {
                        "type": "text",
                        "value": "6.0.0"
                      }
                    ]
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Renamed `cy.route2()` to `cy.intercept()`."
                  }
                ]
              }
            ]
          },
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/app/references/changelog.md#6-0-0",
                    "children": [
                      {
                        "type": "text",
                        "value": "6.0.0"
                      }
                    ]
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Removed `experimentalNetworkStubbing` option and made it the default behavior."
                  }
                ]
              }
            ]
          },
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/app/references/changelog.md#5-1-0",
                    "children": [
                      {
                        "type": "text",
                        "value": "5.1.0"
                      }
                    ]
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Added experimental `cy.route2()` command under `experimentalNetworkStubbing` option."
                  }
                ]
              }
            ]
          }
        ]
      },
      {
        "type": "heading",
        "depth": 2,
        "children": [
          {
            "type": "text",
            "value": "See also"
          }
        ]
      },
      {
        "type": "list",
        "ordered": false,
        "start": null,
        "spread": false,
        "children": [
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/api/commands/as.md",
                    "children": [
                      {
                        "type": "text",
                        "value": "`.as()`"
                      }
                    ]
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/api/commands/wait.md",
                    "children": [
                      {
                        "type": "text",
                        "value": "`cy.wait()`"
                      }
                    ]
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/app/guides/network-requests.md",
                    "children": [
                      {
                        "type": "text",
                        "value": "Network Requests Guide"
                      }
                    ]
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "link",
                    "title": null,
                    "url": "https://github.com/cypress-io/cypress-example-recipes#stubbing-and-spying",
                    "children": [
                      {
                        "type": "text",
                        "value": "Cypress Example Recipes"
                      }
                    ]
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "link",
                    "title": null,
                    "url": "https://github.com/cypress-io/cypress-example-kitchensink/blob/master/cypress/e2e/2-advanced-examples/network_requests.cy.js",
                    "children": [
                      {
                        "type": "text",
                        "value": "Kitchen Sink Examples"
                      }
                    ]
                  }
                ]
              }
            ]
          }
        ]
      },
      {
        "type": "definition",
        "identifier": "staticresponse",
        "label": "staticresponse",
        "title": null,
        "url": "#StaticResponse-objects"
      },
      {
        "type": "definition",
        "identifier": "lifecycle",
        "label": "lifecycle",
        "title": null,
        "url": "#Interception-lifecycle"
      },
      {
        "type": "definition",
        "identifier": "req",
        "label": "req",
        "title": null,
        "url": "#Intercepted-requests"
      },
      {
        "type": "definition",
        "identifier": "req-continue",
        "label": "req-continue",
        "title": null,
        "url": "#Controlling-the-outbound-request-with-reqcontinue"
      },
      {
        "type": "definition",
        "identifier": "req-reply",
        "label": "req-reply",
        "title": null,
        "url": "#Providing-a-stub-response-with-reqreply"
      },
      {
        "type": "definition",
        "identifier": "res",
        "label": "res",
        "title": null,
        "url": "#Intercepted-responses"
      },
      {
        "type": "definition",
        "identifier": "res-send",
        "label": "res-send",
        "title": null,
        "url": "#Ending-the-response-with-ressend"
      },
      {
        "type": "definition",
        "identifier": "match-url",
        "label": "match-url",
        "title": null,
        "url": "#Matching-url"
      },
      {
        "type": "definition",
        "identifier": "glob-match-url",
        "label": "glob-match-url",
        "title": null,
        "url": "#Glob-Pattern-Matching-URLs"
      },
      {
        "type": "definition",
        "identifier": "arg-method",
        "label": "arg-method",
        "title": null,
        "url": "#method-String"
      },
      {
        "type": "definition",
        "identifier": "arg-routehandler",
        "label": "arg-routehandler",
        "title": null,
        "url": "#routeHandler-Function"
      },
      {
        "type": "definition",
        "identifier": "arg-routematcher",
        "label": "arg-routematcher",
        "title": null,
        "url": "#routeMatcher-RouteMatcher"
      }
    ]
  },
  "token_estimate": 8643
}