PageSourceSearch

https://playwright.dev/assets/js/af8f102d.8ddfc92e.js

js playwright.dev collected 2026-09-24 06:54:25 UTC 37,358 bytes, 1 lines download raw bytes

1"use strict";(self.webpackChunkplaywright_dev=self.webpackChunkplaywright_dev||[]).push([["2194"],{13775(e,t,r){r.r(t),r.d(t,{metadata:()=>n,default:()=>h,frontMatter:()=>l,contentTitle:()=>o,toc:()=>c,assets:()=>a});var n=JSON.parse('{"id":"api/class-route","title":"Route","description":"Whenever a network route is set up with page.route() or browserContext.route(), the Route object allows to handle the route.","source":"@site/docs/api/class-route.mdx","sourceDirName":"api","slug":"/api/class-route","permalink":"/docs/next/api/class-route","draft":false,"unlisted":false,"tags":[],"version":"current","frontMatter":{"id":"class-route","title":"Route"},"sidebar":"api","previous":{"title":"Response","permalink":"/docs/next/api/class-response"},"next":{"title":"Screencast","permalink":"/docs/next/api/class-screencast"}}'),s=r(74848),i=r(28453);r(13554),r(41647),r(83137);let l={id:"class-route",title:"Route"},o,a={},c=[{value:"Methods",id:"methods",level:2},{value:"abort",id:"route-abort",level:3},{value:"continue",id:"route-continue",level:3},{value:"fallback",id:"route-fallback",level:3},{value:"fetch",id:"route-fetch",level:3},{value:"fulfill",id:"route-fulfill",level:3},{value:"request",id:"route-request",level:3}];function d(e){let t={a:"a",admonition:"admonition",code:"code",em:"em",h2:"h2",h3:"h3",hr:"hr",li:"li",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,i.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["Whenever a network route is set up with ",(0,s.jsx)(t.a,{href:"/docs/next/api/class-page#page-route",children:"page.route()"})," or ",(0,s.jsx)(t.a,{href:"/docs/next/api/class-browsercontext#browser-context-route",children:"browserContext.route()"}),", the ",(0,s.jsx)(t.code,{children:"Route"})," object allows to handle the route."]}),"\n",(0,s.jsxs)(t.p,{children:["Learn more about ",(0,s.jsx)(t.a,{href:"/docs/next/network",children:"networking"}),"."]}),"\n",(0,s.jsx)(t.hr,{}),"\n",(0,s.jsx)(t.h2,{id:"methods",children:"Methods"}),"\n",(0,s.jsx)(t.h3,{id:"route-abort",children:"abort"}),"\n",(0,s.jsx)("font",{size:"2",style:{position:"relative",top:"-20px"},children:"Added before v1.9"}),"\n",(0,s.jsx)("x-search",{children:"route.abort"}),"\n",(0,s.jsx)(t.p,{children:"Aborts the route's request."}),"\n",(0,s.jsx)(t.p,{children:(0,s.jsx)(t.strong,{children:"Usage"})}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-js",children:"await route.abort();\nawait route.abort(errorCode);\n"})}),"\n",(0,s.jsx)(t.p,{children:(0,s.jsx)(t.strong,{children:"Arguments"})}),"\n",(0,s.jsxs)(t.ul,{children:["\n",(0,s.jsxs)(t.li,{children:["\n",(0,s.jsxs)(t.p,{children:[(0,s.jsx)(t.code,{children:"errorCode"})," ",(0,s.jsx)(t.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type",title:"string",children:"string"})," ",(0,s.jsx)(t.em,{children:"(optional)"}),(0,s.jsx)("a",{"aria-hidden":"true",tabIndex:"-1",class:"list-anchor-link",id:"route-abort-option-error-code"}),(0,s.jsx)("a",{href:"#route-abort-option-error-code",class:"list-anchor",children:"#"})]}),"\n",(0,s.jsxs)(t.p,{children:["Optional error code. Defaults to ",(0,s.jsx)(t.code,{children:"failed"}),", could be one of the following:"]}),"\n",(0,s.jsxs)(t.ul,{children:["\n",(0,s.jsxs)(t.li,{children:[(0,s.jsx)(t.code,{children:"'aborted'"})," - An operation was aborted (due to user action)"]}),"\n",(0,s.jsxs)(t.li,{children:[(0,s.jsx)(t.code,{children:"'accessdenied'"})," - Permission to access a resource, other than the network, was denied"]}),"\n",(0,s.jsxs)(t.li,{children:[(0,s.jsx)(t.code,{children:"'addressunreachable'"})," - The IP address is unreachable. This usually means that there is no route to the specified host or network."]}),"\n",(0,s.jsxs)(t.li,{children:[(0,s.jsx)(t.code,{children:"'blockedbyclient'"})," - The client chose to block the request."]}),"\n",(0,s.jsxs)(t.li,{children:[(0,s.jsx)(t.code,{children:"'blockedbyresponse'"})," - The request failed because the response was delivered along with requirements which are not met ('X-Frame-Options' and 'Content-Security-Policy' ancestor checks, for instance)."]}),"\n",(0,s.jsxs)(t.li,{children:[(0,s.jsx)(t.code,{children:"'connectionaborted'"})," - A connection timed out as a result of not receiving an ACK for data sent."]}),"\n",(0,s.jsxs)(t.li,{children:[(0,s.jsx)(t.code,{children:"'connectionclosed'"})," - A connection was closed (corresponding to a TCP FIN)."]}),"\n",(0,s.jsxs)(t.li,{children:[(0,s.jsx)(t.code,{children:"'connectionfailed'"})," - A connection attempt failed."]}),"\n",(0,s.jsxs)(t.li,{children:[(0,s.jsx)(t.code,{children:"'connectionrefused'"})," - A connection attempt was refused."]}),"\n",(0,s.jsxs)(t.li,{children:[(0,s.jsx)(t.code,{children:"'connectionreset'"})," - A connection was reset (corresponding to a TCP RST)."]}),"\n",(0,s.jsxs)(t.li,{children:[(0,s.jsx)(t.code,{children:"'internetdisconnected'"})," - The Internet connection has been lost."]}),"\n",(0,s.jsxs)(t.li,{children:[(0,s.jsx)(t.code,{children:"'namenotresolved'"})," - The host name could not be resolved."]}),"\n",(0,s.jsxs)(t.li,{children:[(0,s.jsx)(t.code,{children:"'timedout'"})," - An operation timed out."]}),"\n",(0,s.jsxs)(t.li,{children:[(0,s.jsx)(t.code,{children:"'failed'"})," - A generic failure occurred."]}),"\n"]}),"\n"]}),"\n"]}),"\n",(0,s.jsx)(t.p,{children:(0,s.jsx)(t.strong,{children:"Returns"})}),"\n",(0,s.jsxs)(t.ul,{children:["\n",(0,s.jsxs)(t.li,{children:[(0,s.jsx)(t.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise",title:"Promise",children:"Promise"}),"<",(0,s.jsx)(t.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined",title:"void",children:"void"}),">",(0,s.jsx)("a",{"aria-hidden":"true",tabIndex:"-1",class:"list-anchor-link",id:"route-abort-return"}),(0,s.jsx)("a",{href:"#route-abort-return",class:"list-anchor",children:"#"})]}),"\n"]}),"\n",(0,s.jsx)(t.hr,{}),"\n",(0,s.jsx)(t.h3,{id:"route-continue",children:"continue"}),"\n",(0,s.jsx)("font",{size:"2",style:{position:"relative",top:"-20px"},children:"Added before v1.9"}),"\n",(0,s.jsx)("x-search",{children:"route.continue"}),"\n",(0,s.jsx)(t.p,{children:"Sends route's request to the network with optional overrides."}),"\n",(0,s.jsx)(t.p,{children:(0,s.jsx)(t.strong,{children:"Usage"})}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-js",children:"await page.route('**/*', async (route, request) => {\n  // Override headers\n  const headers = {\n    ...request.headers(),\n    foo: 'foo-value', // set \"foo\" header\n    bar: undefined, // remove \"bar\" header\n  };\n  await route.continue({ headers });\n});\n"})}),"\n",(0,s.jsx)(t.p,{children:(0,s.jsx)(t.strong,{children:"Arguments"})}),"\n",(0,s.jsxs)(t.ul,{children:["\n",(0,s.jsxs)(t.li,{children:[(0,s.jsx)(t.code,{children:"options"})," ",(0,s.jsx)(t.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object",title:"Object",children:"Object"})," ",(0,s.jsx)(t.em,{children:"(optional)"}),"\n",(0,s.jsxs)(t.ul,{children:["\n",(0,s.jsxs)(t.li,{children:["\n",(0,s.jsxs)(t.p,{children:[(0,s.jsx)(t.code,{children:"headers"})," ",(0,s.jsx)(t.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object",title:"Object",children:"Object"}),"<",(0,s.jsx)(t.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type",title:"string",children:"string"}),", ",(0,s.jsx)(t.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type",title:"string",children:"string"}),"> ",(0,s.jsx)(t.em,{children:"(optional)"}),(0,s.jsx)("a",{"aria-hidden":"true",tabIndex:"-1",class:"list-anchor-link",id:"route-continue-option-headers"}),(0,s.jsx)("a",{href:"#route-continue-option-headers",class:"list-anchor",children:"#"})]}),"\n",(0,s.jsx)(t.p,{children:"If set changes the request HTTP headers. Header values will be converted to a string."}),"\n"]}),"\n",(0,s.jsxs)(t.li,{children:["\n",(0,s.jsxs)(t.p,{children:[(0,s.jsx)(t.code,{children:"method"})," ",(0,s.jsx)(t.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type",title:"string",children:"string"})," ",(0,s.jsx)(t.em,{children:"(optional)"}),(0,s.jsx)("a",{"aria-hidden":"true",tabIndex:"-1",class:"list-anchor-link",id:"route-continue-option-method"}),(0,s.jsx)("a",{href:"#route-continue-option-method",class:"list-anchor",children:"#"})]}),"\n",(0,s.jsx)(t.p,{children:"If set changes the request method (e.g. GET or POST)."}),"\n"]}),"\n",(0,s.jsxs)(t.li,{children:["\n",(0,s.jsxs)(t.p,{children:[(0,s.jsx)(t.code,{children:"postData"})," ",(0,s.jsx)(t.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type",title:"string",children:"string"})," | ",(0,s.jsx)(t.a,{href:"https://nodejs.org/api/buffer.html#buffer_class_buffer",title:"Buffer",children:"Buffer"})," | ",(0,s.jsx)(t.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#Description",title:"Serializable",children:"Serializable"})," ",(0,s.jsx)(t.em,{children:"(optional)"}),(0,s.jsx)("a",{"aria-hidden":"true",tabIndex:"-1",class:"list-anchor-link",id:"route-continue-option-post-data"}),(0,s.jsx)("a",{href:"#route-continue-option-post-data",class:"list-anchor",children:"#"})]}),"\n",(0,s.jsx)(t.p,{children:"If set changes the post data of request."}),"\n"]}),"\n",(0,s.jsxs)(t.li,{children:["\n",(0,s.jsxs)(t.p,{children:[(0,s.jsx)(t.code,{children:"url"})," ",(0,s.jsx)(t.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type",title:"string",children:"string"})," ",(0,s.jsx)(t.em,{children:"(optional)"}),(0,s.jsx)("a",{"aria-hidden":"true",tabIndex:"-1",class:"list-anchor-link",id:"route-continue-option-url"}),(0,s.jsx)("a",{href:"#route-continue-option-url",class:"list-anchor",children:"#"})]}),"\n",(0,s.jsx)(t.p,{children:"If set changes the request URL. New URL must have same protocol as original one."}),"\n"]}),"\n"]}),"\n"]}),"\n"]}),"\n",(0,s.jsx)(t.p,{children:(0,s.jsx)(t.strong,{children:"Returns"})}),"\n",(0,s.jsxs)(t.ul,{children:["\n",(0,s.jsxs)(t.li,{children:[(0,s.jsx)(t.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise",title:"Promise",children:"Promise"}),"<",(0,s.jsx)(t.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined",title:"void",children:"void"}),">",(0,s.jsx)("a",{"aria-hidden":"true",tabIndex:"-1",class:"list-anchor-link",id:"route-continue-return"}),(0,s.jsx)("a",{href:"#route-continue-return",class:"list-anchor",children:"#"})]}),"\n"]}),"\n",(0,s.jsx)(t.p,{children:(0,s.jsx)(t.strong,{children:"Details"})}),"\n",(0,s.jsxs)(t.p,{children:["The ",(0,s.jsx)(t.a,{href:"/docs/next/api/class-route#route-continue-option-headers",children:"headers"}
1)," option applies to both the routed request and any redirects it initiates. However, ",(0,s.jsx)(t.a,{href:"/docs/next/api/class-route#route-continue-option-url",children:"url"}),", ",(0,s.jsx)(t.a,{href:"/docs/next/api/class-route#route-continue-option-method",children:"method"}),", and ",(0,s.jsx)(t.a,{href:"/docs/next/api/class-route#route-continue-option-post-data",children:"postData"})," only apply to the original request and are not carried over to redirected requests."]}),"\n",(0,s.jsxs)(t.p,{children:[(0,s.jsx)(t.a,{href:"/docs/next/api/class-route#route-continue",children:"route.continue()"})," will immediately send the request to the network, other matching handlers won't be invoked. Use ",(0,s.jsx)(t.a,{href:"/docs/next/api/class-route#route-fallback",children:"route.fallback()"})," If you want next matching handler in the chain to be invoked."]}),"\n",(0,s.jsxs)(t.admonition,{type:"warning",children:[(0,s.jsxs)(t.p,{children:["Some request headers are ",(0,s.jsx)(t.strong,{children:"forbidden"})," and cannot be overridden (for example, ",(0,s.jsx)(t.code,{children:"Cookie"}),", ",(0,s.jsx)(t.code,{children:"Host"}),", ",(0,s.jsx)(t.code,{children:"Content-Length"})," and others, see ",(0,s.jsx)(t.a,{href:"https://developer.mozilla.org/en-US/docs/Glossary/Forbidden_request_header",children:"this MDN page"})," for full list). If an override is provided for a forbidden header, it will be ignored and the original request header will be used."]}),(0,s.jsxs)(t.p,{children:["To set custom cookies, use ",(0,s.jsx)(t.a,{href:"/docs/next/api/class-browsercontext#browser-context-add-cookies",children:"browserContext.addCookies()"}),"."]})]}),"\n",(0,s.jsx)(t.hr,{}),"\n",(0,s.jsx)(t.h3,{id:"route-fallback",children:"fallback"}),"\n",(0,s.jsx)("font",{size:"2",style:{position:"relative",top:"-20px"},children:"Added in: v1.23"}),"\n",(0,s.jsx)("x-search",{children:"route.fallback"}),"\n",(0,s.jsxs)(t.p,{children:["Continues route's request with optional overrides. The method is similar to ",(0,s.jsx)(t.a,{href:"/docs/next/api/class-route#route-continue",children:"route.continue()"})," with the difference that other matching handlers will be invoked before sending the request."]}),"\n",(0,s.jsx)(t.p,{children:(0,s.jsx)(t.strong,{children:"Usage"})}),"\n",(0,s.jsx)(t.p,{children:"When several routes match the given pattern, they run in the order opposite to their registration. That way the last registered route can always override all the previous ones. In the example below, request will be handled by the bottom-most handler first, then it'll fall back to the previous one and in the end will be aborted by the first registered route."}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-js",children:"await page.route('**/*', async route => {\n  // Runs last.\n  await route.abort();\n});\nawait page.route('**/*', async route => {\n  // Runs second.\n  await route.fallback();\n});\nawait page.route('**/*', async route => {\n  // Runs first.\n  await route.fallback();\n});\n"})}),"\n",(0,s.jsx)(t.p,{children:"Registering multiple routes is useful when you want separate handlers to handle different kinds of requests, for example API calls vs page resources or GET requests vs POST requests as in the example below."}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-js",children:"// Handle GET requests.\nawait page.route('**/*', async route => {\n  if (route.request().method() !== 'GET') {\n    await route.fallback();\n    return;\n  }\n  // Handling GET only.\n  // ...\n});\n\n// Handle POST requests.\nawait page.route('**/*', async route => {\n  if (route.request().method() !== 'POST') {\n    await route.fallback();\n    return;\n  }\n  // Handling POST only.\n  // ...\n});\n"})}),"\n",(0,s.jsx)(t.p,{children:"One can also modify request while falling back to the subsequent handler, that way intermediate route handler can modify url, method, headers and postData of the request."}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-js",children:"await page.route('**/*', async (route, request) => {\n  // Override headers\n  const headers = {\n    ...request.headers(),\n    foo: 'foo-value', // set \"foo\" header\n    bar: undefined, // remove \"bar\" header\n  };\n  await route.fallback({ headers });\n});\n"})}),"\n",(0,s.jsxs)(t.p,{children:["Use ",(0,s.jsx)(t.a,{href:"/docs/next/api/class-route#route-continue",children:"route.continue()"})," to immediately send the request to the network, other matching handlers won't be invoked in that case."]}),"\n",(0,s.jsx)(t.p,{children:(0,s.jsx)(t.strong,{children:"Arguments"})}),"\n",(0,s.jsxs)(t.ul,{children:["\n",(0,s.jsxs)(t.li,{children:[(0,s.jsx)(t.code,{children:"options"})," ",(0,s.jsx)(t.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object",title:"Object",children:"Object"})," ",(0,s.jsx)(t.em,{children:"(optional)"}),"\n",(0,s.jsxs)(t.ul,{children:["\n",(0,s.jsxs)(t.li,{children:["\n",(0,s.jsxs)(t.p,{children:[(0,s.jsx)(t.code,{children:"headers"})," ",(0,s.jsx)(t.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object",title:"Object",children:"Object"}),"<",(0,s.jsx)(t.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type",title:"string",children:"string"}),", ",(0,s.jsx)(t.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type",title:"string",children:"string"}),"> ",(0,s.jsx)(t.em,{children:"(optional)"}),(0,s.jsx)("a",{"aria-hidden":"true",tabIndex:"-1",class:"list-anchor-link",id:"route-fallback-option-headers"}),(0,s.jsx)("a",{href:"#route-fallback-option-headers",class:"list-anchor",children:"#"})]}),"\n",(0,s.jsx)(t.p,{children:"If set changes the request HTTP headers. Header values will be converted to a string."}),"\n"]}),"\n",(0,s.jsxs)(t.li,{children:["\n",(0,s.jsxs)(t.p,{children:[(0,s.jsx)(t.code,{children:"method"})," ",(0,s.jsx)(t.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type",title:"string",children:"string"})," ",(0,s.jsx)(t.em,{children:"(optional)"}),(0,s.jsx)("a",{"aria-hidden":"true",tabIndex:"-1",class:"list-anchor-link",id:"route-fallback-option-method"}),(0,s.jsx)("a",{href:"#route-fallback-option-method",class:"list-anchor",children:"#"})]}),"\n",(0,s.jsx)(t.p,{children:"If set changes the request method (e.g. GET or POST)."}),"\n"]}),"\n",(0,s.jsxs)(t.li,{children:["\n",(0,s.jsxs)(t.p,{children:[(0,s.jsx)(t.code,{children:"postData"})," ",(0,s.jsx)(t.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type",title:"string",children:"string"})," | ",(0,s.jsx)(t.a,{href:"https://nodejs.org/api/buffer.html#buffer_class_buffer",title:"Buffer",children:"Buffer"})," | ",(0,s.jsx)(t.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#Description",title:"Serializable",children:"Serializable"})," ",(0,s.jsx)(t.em,{children:"(optional)"}),(0,s.jsx)("a",{"aria-hidden":"true",tabIndex:"-1",class:"list-anchor-link",id:"route-fallback-option-post-data"}),(0,s.jsx)("a",{href:"#route-fallback-option-post-data",class:"list-anchor",children:"#"})]}),"\n",(0,s.jsx)(t.p,{children:"If set changes the post data of request."}),"\n"]}),"\n",(0,s.jsxs)(t.li,{children:["\n",(0,s.jsxs)(t.p,{children:[(0,s.jsx)(t.code,{children:"url"})," ",(0,s.jsx)(t.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type",title:"string",children:"string"})," ",(0,s.jsx)(t.em,{children:"(optional)"}),(0,s.jsx)("a",{"aria-hidden":"true",tabIndex:"-1",class:"list-anchor-link",id:"route-fallback-option-url"}),(0,s.jsx)("a",{href:"#route-fallback-option-url",class:"list-anchor",children:"#"})]}),"\n",(0,s.jsx)(t.p,{children:"If set changes the request URL. New URL must have same protocol as original one. Changing the URL won't affect the route matching, all the routes are matched using the original request URL."}),"\n"]}),"\n"]}),"\n"]}),"\n"]}),"\n",(0,s.jsx)(t.p,{children:(0,s.jsx)(t.strong,{children:"Returns"})}),"\n",(0,s.jsxs)(t.ul,{children:["\n",(0,s.jsxs)(t.li,{children:[(0,s.jsx)(t.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise",title:"Promise",children:"Promise"}),"<",(0,s.jsx)(t.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined",title:"void",children:"void"}),">",(0,s.jsx)("a",{"aria-hidden":"true",tabIndex:"-1",class:"list-anchor-link",id:"route-fallback-return"}),(0,s.jsx)("a",{href:"#route-fallback-return",class:"list-anchor",children:"#"})]}),"\n"]}),"\n",(0,s.jsx)(t.hr,{}),"\n",(0,s.jsx)(t.h3,{id:"route-fetch",children:"fetch"}),"\n",(0,s.jsx)("font",{size:"2",style:{position:"relative",top:"-20px"},children:"Added in: v1.29"}),"\n",(0,s.jsx)("x-search",{children:"route.fetch"}),"\n",(0,s.jsx)(t.p,{children:"Performs the request and fetches result without fulfilling it, so that the response could be modified and then fulfilled."}),"\n",(0,s.jsx)(t.p,{children:(0,s.jsx)(t.strong,{children:"Usage"})}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-js",children:"await page.route('https://dog.ceo/api/breeds/list/all', async route => {\n  const response = await route.fetch();\n  const json = await response.json();\n  json.message['big_red_dog'] = [];\n  await route.fulfill({ response, json });\n});\n"})}),"\n",(0,s.jsx)(t.p,{children:(0,s.jsx)(t.strong,{children:"Arguments"})}),"\n",(0,s.jsxs)(t.ul,{children:["\n",(0,s.jsxs)(t.li,{children:[(0,s.jsx)(t.code,{children:"options"})," ",(0,s.jsx)(t.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object",title:"Object",children:"Object"})," ",(0,s.jsx)(t.em,{children:"(optional)"}),"\n",(0,s.jsxs)(t.ul,{children:["\n",(0,s.jsxs)(t.li,{children:["\n",(0,s.jsxs)(t.p,{children:[(0,s.jsx)(t.code,{children:"headers"})," ",(0,s.jsx)(t.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object",title:"Object",children:"Object"}),"<",(0,s.jsx)(t.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type",title:"string",children:"string"}),", ",(0,s.jsx)(t.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type",title:"string",children:"string"}),"> ",(0,s.jsx)(t.em,{children:"(optional)"}),(0,s.jsx)("a",{"aria-hidden":"true",tabIndex:"-1",class:"list-anchor-link",id:"route-fetch-option-headers"}),(0,s.jsx)("a",{href:"#route-fetch-option-headers",class:"list-anchor",children:"#"})]}),"\n",(0,s.jsx)(t.p,{children:"If set changes the request HTTP headers. Header values will be converted to a string."}),"\n"]}),"\n",(0,s.jsxs)(t.li,{children:["\n",(0,s.jsxs)(t.p,{children:[(0,s.jsx)(t.code,{children:"maxRedirects"})," ",(0,s.jsx)(t.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type",title:"Number",children:"number"})," ",(0,s.jsx)(t.em,{children:"(optional)"})," ",(0,s.jsx)("font",{size:"2",children:"Added in: v1.31"}),(0,s.jsx)("a",{"aria-hidden":"true",tabIndex:"-1",class:"list-anchor-link",id:"route-fetch-option-max-redirects"}),(0,s.jsx)("a",{href:"#route-fetch-option-max-redirects",class:"list-anchor",children:"#"})]}),"\n",(0,s.jsxs)(t.p,{children:["Maximum number of request redirects that will be followed automatically. An error will be thrown if the number is exceeded. Defaults to ",(0,s.jsx)(t.code,{children:"20"}),". Pass ",(0,s.jsx)(t.code,{children:"0"})," to not follow redirects."]}),"\n"]}),"\n",(0,s.jsxs)(t.li,{children:["\n",(0,s.jsxs)(t.p,{children:[(0,s.jsx)(t.code,{children:"maxRetries"})," ",(0,s.jsx)(t.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type",title:"Number",children:"number"})," ",(0,s.jsx)(t.em,{children:"(optional)"})," ",(0,s.jsx)("font",{size:"2",children:"Added in: v1.46"}),(0,s.jsx)("a",{"aria-hidden":"true",tabIndex:"-1",class:"list-anchor-link",id:"route-fetch-option-max-retries"}),(0,s.jsx)("a",{href:"#route-fetch-option-max-retries",class:"list-anchor",children:"#"})]}),"\n",(0,s.jsxs)(t.p,{children:["Maximum number of times network errors should be retried. Currently only ",(0,s.jsx)(t.code,{children:"ECONNRESET"})," error is retried. Does not retry based on HTTP response codes. An error will be thrown if the limit is exceeded. Defaults to ",(0,s.jsx)(t.code,{children:"0"})," - no retries."]}),"\n"]}),"\n",(0,s.jsxs)(t.li,{children:["\n",(0,s.jsxs)(t.p,{children:[(0,s.jsx)(t.code,{children:"method"})," ",(0,s.jsx)(t.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type",title:"string",children:"string"})," ",(0,s.jsx)(t.em,{children:"(optional)"}),(0,s.jsx)("a",{"aria-hidden":"true",tabIndex:"-1",class:"list-anchor-link",id:"route-fetch-option-method"}),(0,s.jsx)("a",{href:"#route-fetch-option-method",class:"list-anchor",children:"#"})]}),"\n",(0,s.jsx)(t.p,{children:"If set changes the request method (e.g. GET or POST)."}),"\n"]}),"\n",(0,s.jsxs)(t.li,{children:["\n",(0,s.jsxs)(t.p,{children:[(0,s.jsx)(t.code,{children:"postData"})," ",(0,s.jsx)(t.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type",title:"string",children:"string"})," | ",(0,s.jsx)(t.a,{href:"https://nodejs.org/api/buffer.html#buffer_class_buffer",title:"Buffer",children:"Buffer"})," | ",(0,s.jsx)(t.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#Description",title:"Serializable",children:"Serializable"})," ",(0,s.jsx)(t.em,{children:"(optional)"}),(0,s.jsx)("a",{"aria-hidden":"true",tabIndex:"-1",class:"list-anchor-link",id:"route-fetch-option-post-data"}),(0,s.jsx)("a",{href:"#route-fetch-option-post-data",class:"list-anchor",children:"#"})]}),"\n",(0,s.jsxs)(t.p,{children:["Allows to set post data of the request. If the data parameter is an object, it will be serialized to json string and ",(0,s.jsx)(t.code,{children:"content-type"})," header will be set to ",(0,s.jsx)(t.code,{children:"application/json"})," if not explicitly set. Otherwise the ",(0,s.jsx)(t.code,{children:"content-type"})," header will be set to ",(0,s.jsx)(t.code,{children:"application/octet-stream"})," if not explicitly set."]}),"\n"]}),"\n",(0,s.jsxs)(t.li,{children:["\n",(0,s.jsxs)(t.p,{children:[(0,s.jsx)(t.code,{children:"signal"})," ",(0,s.jsx)(t.a,{href:"https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal",title:"AbortSignal",children:"AbortSignal"})," ",(0,s.jsx)(t.em,{children:"(optional)"})," ",(0,s.jsx)("font",{size:"2",children:"Added in: v1.62"}),(0,s.jsx)("a",{"aria-hidden":"true",tabIndex:"-1",class:"list-anchor-link",id:"route-fetch-option-signal"}),(0,s.jsx)("a",{href:"#route-fetch-option-signal",class:"list-anchor",children:"#"})]}),"\n",(0,s.jsxs)(t.p,{children:["Allows to cancel the operation using an ",(0,s.jsx)(t.a,{href:"https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal",children:(0,s.jsx)(t.code,{children:"AbortSignal"})}),". If the signal is aborted, the operation will be aborted and throw an error. Note that providing a signal does not disable the default timeout, which can be changed using ",(0,s.jsx)(t.a,{href:"/docs/next/api/class-browsercontext#browser-context-set-default-timeout",children:"browserContext.setDefaultTimeout()"})," or ",(0,s.jsx)(t.a,{href:"/docs/next/api/class-page#page-set-default-timeout",children:"page.setDefaultTimeout()"}),"; pass ",(0,s.jsx)(t.code,{children:"timeout: 0"})," to disable the timeout entirely."]}),"\n"]}),"\n",(0,s.jsxs)(t.li,{children:["\n",(0,s.jsxs)(t.p,{children:[(0,s.jsx)(t.code,{children:"timeout"})," ",(0,s.jsx)(t.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type",title:"Number",children:"number"})," ",(0,s.jsx)(t.em,{children:"(optional)"})," ",(0,s.jsx)("font",{size:"2",children:"Added in: v1.33"}),(0,s.jsx)("a",{"aria-hidden":"true",tabIndex:"-1",class:"list-anchor-link",id:"route-fetch-option-timeout"}),(0,s.jsx)("a",{href:"#route-fetch-option-timeout",class:"list-anchor",children:"#"})]}),"\n",(0,s.jsxs)(t.p,{children:["Request timeout in milliseconds. Defaults to ",(0,s.jsx)(t.code,{children:"30000"})," (30 secon
1ds). Pass ",(0,s.jsx)(t.code,{children:"0"})," to disable timeout."]}),"\n"]}),"\n",(0,s.jsxs)(t.li,{children:["\n",(0,s.jsxs)(t.p,{children:[(0,s.jsx)(t.code,{children:"url"})," ",(0,s.jsx)(t.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type",title:"string",children:"string"})," ",(0,s.jsx)(t.em,{children:"(optional)"}),(0,s.jsx)("a",{"aria-hidden":"true",tabIndex:"-1",class:"list-anchor-link",id:"route-fetch-option-url"}),(0,s.jsx)("a",{href:"#route-fetch-option-url",class:"list-anchor",children:"#"})]}),"\n",(0,s.jsx)(t.p,{children:"If set changes the request URL. New URL must have same protocol as original one."}),"\n"]}),"\n"]}),"\n"]}),"\n"]}),"\n",(0,s.jsx)(t.p,{children:(0,s.jsx)(t.strong,{children:"Returns"})}),"\n",(0,s.jsxs)(t.ul,{children:["\n",(0,s.jsxs)(t.li,{children:[(0,s.jsx)(t.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise",title:"Promise",children:"Promise"}),"<",(0,s.jsx)(t.a,{href:"/docs/next/api/class-apiresponse",title:"APIResponse",children:"APIResponse"}),">",(0,s.jsx)("a",{"aria-hidden":"true",tabIndex:"-1",class:"list-anchor-link",id:"route-fetch-return"}),(0,s.jsx)("a",{href:"#route-fetch-return",class:"list-anchor",children:"#"})]}),"\n"]}),"\n",(0,s.jsx)(t.p,{children:(0,s.jsx)(t.strong,{children:"Details"})}),"\n",(0,s.jsxs)(t.p,{children:["Note that ",(0,s.jsx)(t.a,{href:"/docs/next/api/class-route#route-fetch-option-headers",children:"headers"})," option will apply to the fetched request as well as any redirects initiated by it. If you want to only apply ",(0,s.jsx)(t.a,{href:"/docs/next/api/class-route#route-fetch-option-headers",children:"headers"})," to the original request, but not to redirects, look into ",(0,s.jsx)(t.a,{href:"/docs/next/api/class-route#route-continue",children:"route.continue()"})," instead."]}),"\n",(0,s.jsx)(t.hr,{}),"\n",(0,s.jsx)(t.h3,{id:"route-fulfill",children:"fulfill"}),"\n",(0,s.jsx)("font",{size:"2",style:{position:"relative",top:"-20px"},children:"Added before v1.9"}),"\n",(0,s.jsx)("x-search",{children:"route.fulfill"}),"\n",(0,s.jsx)(t.p,{children:"Fulfills route's request with given response."}),"\n",(0,s.jsx)(t.p,{children:(0,s.jsx)(t.strong,{children:"Usage"})}),"\n",(0,s.jsx)(t.p,{children:"An example of fulfilling all requests with 404 responses:"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-js",children:"await page.route('**/*', async route => {\n  await route.fulfill({\n    status: 404,\n    contentType: 'text/plain',\n    body: 'Not Found!'\n  });\n});\n"})}),"\n",(0,s.jsx)(t.p,{children:"An example of serving static file:"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-js",children:"await page.route('**/xhr_endpoint', route => route.fulfill({ path: 'mock_data.json' }));\n"})}),"\n",(0,s.jsx)(t.p,{children:(0,s.jsx)(t.strong,{children:"Arguments"})}),"\n",(0,s.jsxs)(t.ul,{children:["\n",(0,s.jsxs)(t.li,{children:[(0,s.jsx)(t.code,{children:"options"})," ",(0,s.jsx)(t.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object",title:"Object",children:"Object"})," ",(0,s.jsx)(t.em,{children:"(optional)"}),"\n",(0,s.jsxs)(t.ul,{children:["\n",(0,s.jsxs)(t.li,{children:["\n",(0,s.jsxs)(t.p,{children:[(0,s.jsx)(t.code,{children:"body"})," ",(0,s.jsx)(t.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type",title:"string",children:"string"})," | ",(0,s.jsx)(t.a,{href:"https://nodejs.org/api/buffer.html#buffer_class_buffer",title:"Buffer",children:"Buffer"})," ",(0,s.jsx)(t.em,{children:"(optional)"}),(0,s.jsx)("a",{"aria-hidden":"true",tabIndex:"-1",class:"list-anchor-link",id:"route-fulfill-option-body"}),(0,s.jsx)("a",{href:"#route-fulfill-option-body",class:"list-anchor",children:"#"})]}),"\n",(0,s.jsx)(t.p,{children:"Response body."}),"\n"]}),"\n",(0,s.jsxs)(t.li,{children:["\n",(0,s.jsxs)(t.p,{children:[(0,s.jsx)(t.code,{children:"contentType"})," ",(0,s.jsx)(t.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type",title:"string",children:"string"})," ",(0,s.jsx)(t.em,{children:"(optional)"}),(0,s.jsx)("a",{"aria-hidden":"true",tabIndex:"-1",class:"list-anchor-link",id:"route-fulfill-option-content-type"}),(0,s.jsx)("a",{href:"#route-fulfill-option-content-type",class:"list-anchor",children:"#"})]}
1),"\n",(0,s.jsxs)(t.p,{children:["If set, equals to setting ",(0,s.jsx)(t.code,{children:"Content-Type"})," response header."]}),"\n"]}),"\n",(0,s.jsxs)(t.li,{children:["\n",(0,s.jsxs)(t.p,{children:[(0,s.jsx)(t.code,{children:"headers"})," ",(0,s.jsx)(t.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object",title:"Object",children:"Object"}),"<",(0,s.jsx)(t.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type",title:"string",children:"string"}),", ",(0,s.jsx)(t.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type",title:"string",children:"string"}),"> ",(0,s.jsx)(t.em,{children:"(optional)"}),(0,s.jsx)("a",{"aria-hidden":"true",tabIndex:"-1",class:"list-anchor-link",id:"route-fulfill-option-headers"}),(0,s.jsx)("a",{href:"#route-fulfill-option-headers",class:"list-anchor",children:"#"})]}),"\n",(0,s.jsx)(t.p,{children:"Response headers. Header values will be converted to a string."}),"\n"]}),"\n",(0,s.jsxs)(t.li,{children:["\n",(0,s.jsxs)(t.p,{children:[(0,s.jsx)(t.code,{children:"json"})," ",(0,s.jsx)(t.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#Description",title:"Serializable",children:"Serializable"})," ",(0,s.jsx)(t.em,{children:"(optional)"})," ",(0,s.jsx)("font",{size:"2",children:"Added in: v1.29"}),(0,s.jsx)("a",{"aria-hidden":"true",tabIndex:"-1",class:"list-anchor-link",id:"route-fulfill-option-json"}),(0,s.jsx)("a",{href:"#route-fulfill-option-json",class:"list-anchor",children:"#"})]}),"\n",(0,s.jsxs)(t.p,{children:["JSON response. This method will set the content type to ",(0,s.jsx)(t.code,{children:"application/json"})," if not set."]}),"\n"]}),"\n",(0,s.jsxs)(t.li,{children:["\n",(0,s.jsxs)(t.p,{children:[(0,s.jsx)(t.code,{children:"path"})," ",(0,s.jsx)(t.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type",title:"string",children:"string"})," ",(0,s.jsx)(t.em,{children:"(optional)"}),(0,s.jsx)("a",{"aria-hidden":"true",tabIndex:"-1",class:"list-anchor-link",id:"route-fulfill-option-path"}),(0,s.jsx)("a",{href:"#route-fulfill-option-path",class:"list-anchor",children:"#"})]}),"\n",(0,s.jsxs)(t.p,{children:["File path to respond with. The content type will be inferred from file extension. If ",(0,s.jsx)(t.code,{children:"path"})," is a relative path, then it is resolved relative to the current working directory."]}),"\n"]}),"\n",(0,s.jsxs)(t.li,{children:["\n",(0,s.jsxs)(t.p,{children:[(0,s.jsx)(t.code,{children:"response"})," ",(0,s.jsx)(t.a,{href:"/docs/next/api/class-apiresponse",title:"APIResponse",children:"APIResponse"})," ",(0,s.jsx)(t.em,{children:"(optional)"})," ",(0,s.jsx)("font",{size:"2",children:"Added in: v1.15"}),(0,s.jsx)("a",{"aria-hidden":"true",tabIndex:"-1",class:"list-anchor-link",id:"route-fulfill-option-response"}),(0,s.jsx)("a",{href:"#route-fulfill-option-response",class:"list-anchor",children:"#"})]}),"\n",(0,s.jsxs)(t.p,{children:[(0,s.jsx)(t.a,{href:"/docs/next/api/class-apiresponse",title:"APIResponse",children:"APIResponse"})," to fulfill route's request with. Individual fields of the response (such as headers) can be overridden using fulfill options."]}),"\n"]}),"\n",(0,s.jsxs)(t.li,{children:["\n",(0,s.jsxs)(t.p,{children:[(0,s.jsx)(t.code,{children:"status"})," ",(0,s.jsx)(t.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type",title:"Number",children:"number"})," ",(0,s.jsx)(t.em,{children:"(optional)"}),(0,s.jsx)("a",{"aria-hidden":"true",tabIndex:"-1",class:"list-anchor-link",id:"route-fulfill-option-status"}),(0,s.jsx)("a",{href:"#route-fulfill-option-status",class:"list-anchor",children:"#"})]}),"\n",(0,s.jsxs)(t.p,{children:["Response status code, defaults to ",(0,s.jsx)(t.code,{children:"200"}),"."]}),"\n"]}),"\n"]}),"\n"]}),"\n"]}),"\n",(0,s.jsx)(t.p,{children:(0,s.jsx)(t.strong,{children:"Returns"})}),"\n",(0,s.jsxs)(t.ul,{children:["\n",(0,s.jsxs)(t.li,{children:[(0,s.jsx)(t.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise",title:"Promise",children:"Promise"}),"<",(0,s.jsx)(t.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined",title:"void",children:"void"}),">",(0,s.jsx)("a",{"aria-hidden":"true",tabIndex:"-1",class:"list-anchor-link",id:"route-fulfill-return"}),(0,s.jsx)("a",{href:"#route-fulfill-return",class:"list-anchor",children:"#"})]}),"\n"]}),"\n",(0,s.jsx)(t.hr,{}),"\n",(0,s.jsx)(t.h3,{id:"route-request",children:"request"}),"\n",(0,s.jsx)("font",{size:"2",style:{position:"relative",top:"-20px"},children:"Added before v1.9"}),"\n",(0,s.jsx)("x-search",{children:"route.request"}),"\n",(0,s.jsx)(t.p,{children:"A request to be routed."}),"\n",(0,s.jsx)(t.p,{children:(0,s.jsx)(t.strong,{children:"Usage"})}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-js",children:"route.request();\n"})}),"\n",(0,s.jsx)(t.p,{children:(0,s.jsx)(t.strong,{children:"Returns"})}),"\n",(0,s.jsxs)(t.ul,{children:["\n",(0,s.jsxs)(t.li,{children:[(0,s.jsx)(t.a,{href:"/docs/next/api/class-request",title:"Request",children:"Request"}),(0,s.jsx)("a",{"aria-hidden":"true",tabIndex:"-1",class:"list-anchor-link",id:"route-request-return"}),(0,s.jsx)("a",{href:"#route-request-return",class:"list-anchor",children:"#"})]}),"\n"]})]})}function h(e={}){let{wrapper:t}={...(0,i.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.jsx)(d,{...e})}):d(e)}}}]);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.