Skip to main content
The Request class represents network requests made by pages. Whenever a page makes a request, the following events are emitted:
  • page.on('request') - emitted when the request is issued
  • page.on('response') - emitted when the response is received

Methods

url

Returns the URL of the request.
Returns: string

resourceType

Returns the resource type of the request.
Returns: string Possible values: document, stylesheet, image, media, font, script, texttrack, xhr, fetch, eventsource, websocket, manifest, other

method

Returns the HTTP method of the request.
Returns: string

postData

Returns the request’s post data as a string.
Returns: string | null

postDataBuffer

Returns the request’s post data as a Buffer.
Returns: Buffer | null

postDataJSON

Parses the request’s post data as JSON.
Returns: Object | null Automatically handles both JSON and form-encoded data.

headers

Returns the request headers.
Returns: Object
This method returns provisional headers. Use allHeaders() for actual headers sent over the network.

allHeaders

Returns all request headers.
Returns: Promise<Object>

headersArray

Returns the request headers as an array of objects.
Returns: Promise<Array<{name: string, value: string}>>

headerValue

Returns the value of a specific header.
string
required
The header name (case-insensitive)
Returns: Promise<string | null>

response

Returns the response for this request.
Returns: Promise<Response | null>

frame

Returns the frame that initiated the request.
Returns: Frame
Throws an error for service worker requests.

isNavigationRequest

Returns whether this is a navigation request.
Returns: boolean

redirectedFrom

Returns the request that was redirected to this request.
Returns: Request | null

redirectedTo

Returns the request that this request was redirected to.
Returns: Request | null

failure

Returns error details if the request failed.
Returns: {errorText: string} | null

timing

Returns timing information for the request.
Returns: Object Returned object properties:
  • startTime: number
  • domainLookupStart: number
  • domainLookupEnd: number
  • connectStart: number
  • secureConnectionStart: number
  • connectEnd: number
  • requestStart: number
  • responseStart: number
  • responseEnd: number

sizes

Returns sizes information for the request.
Returns: Promise<Object> Returned object properties:
  • requestBodySize: number
  • requestHeadersSize: number
  • responseBodySize: number
  • responseHeadersSize: number

Example Usage

Monitor API Requests

Log Failed Requests

Inspect Request Headers