new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

Playwright · API reference · all subjects

request/methods

26 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

Request.allHeaders async method

Request.allHeaders is an async method introduced in v1.15 that returns an Object with all the request HTTP headers associated with the request. The header names are lower-cased. The return type is Object<string, string>.

Request.failure method

Request.failure is a method introduced in v1.8 that returns null or string (or null or Object in JavaScript). The method returns null unless the request has failed as reported by the requestfailed event. In JavaScript, the Object return type has errorText property of type string containing a human-readable error message, for example 'net::ERR_FAILED'.

Request.failure method example - log failed requests

Example in JavaScript: page.on('requestfailed', request => { console.log(request.url() + ' ' + request.failure().errorText); });

Request.frame method

Request.frame is a method introduced in v1.8 that returns a Frame object. It returns the Frame that initiated this request. Note that in some cases the frame is not available and this method will throw. This occurs when the request originates in a Service Worker (check with request.serviceWorker()) or when a navigation request is issued before the corresponding frame is created (check with Request.isNavigationRequest).

Request.frame method example - handle all cases

Example in JavaScript that handles all cases including service worker and navigation requests: if (request.serviceWorker()) console.log(`request ${request.url()} from a service worker`); else if (request.isNavigationRequest()) console.log(`request ${request.url()} is a navigation request`); else console.log(`request ${request.url()} from a frame ${request.frame().url()}`);

Request.headers method

Request.headers is a method introduced in v1.8 that returns an Object with the request HTTP headers. The header names are lower-cased. This method does not return security-related headers including cookie-related ones. Use Request.allHeaders for a complete list of headers that includes cookie information.

Request.headersArray async method

Request.headersArray is an async method introduced in v1.15 that returns an Array of Objects with alias HttpHeader (or Header in C#). Each object has properties: name (string) - name of the header, and value (string) - value of the header. Unlike Request.allHeaders, header names are NOT lower-cased. Headers with multiple entries such as Set-Cookie appear in the array multiple times.

Request.headerValue async method

Request.headerValue is an async method introduced in v1.15 that takes a parameter name (string) - the name of the header. It returns null or string. The method returns the value of the header matching the name. The name is case-insensitive.

Request.isNavigationRequest method

Request.isNavigationRequest is a method introduced in v1.8 that returns a boolean indicating whether this request is driving a frame's navigation. Some navigation requests are issued before the corresponding frame is created and therefore do not have Request.frame available.

Request.method method

Request.method is a method introduced in v1.8 that returns a string. It returns the request's HTTP method (GET, POST, etc.).

Request.postData method

Request.postData is a method introduced in v1.8 that returns null or string. It returns the request's post body, if any.

Request.postDataBuffer method

Request.postDataBuffer is a method introduced in v1.8 that returns null or Buffer. It returns the request's post body in binary form, if any.

Request.postDataJSON method

Request.postDataJSON is a method introduced in v1.8 (v1.12 for C#) that returns null or Serializable (null or JsonElement in C#). It returns the parsed request's body for form-urlencoded and JSON as a fallback if any. When the content-type is application/x-www-form-urlencoded, a key/value object of the values is returned. Otherwise it is parsed as JSON. Available in JavaScript, Python, and C#.

Request.redirectedFrom method

Request.redirectedFrom is a method introduced in v1.8 that returns null or Request. It returns the Request object that was redirected by the server to this one, if any. When the server responds with a redirect, Playwright creates a new Request object. The two requests are connected by redirectedFrom() and redirectedTo() methods. When multiple server redirects have happened, it is possible to construct the whole redirect chain by repeatedly calling redirectedFrom().

Request.redirectedFrom method example - redirect chain

Example in JavaScript: const response = await page.goto('http://example.com'); console.log(response.request().redirectedFrom().url()); // 'http://example.com'

Request.redirectedFrom method example - no redirect

Example in JavaScript when there is no redirect: const response = await page.goto('https://google.com'); console.log(response.request().redirectedFrom()); // null

Request.redirectedTo method

Request.redirectedTo is a method introduced in v1.8 that returns null or Request. It returns a new Request object issued by the browser if the server responded with a redirect. This method is the opposite of Request.redirectedFrom.

Request.redirectedTo method example

Example in JavaScript: console.log(request.redirectedFrom().redirectedTo() === request); // true

Request.resourceType method

Request.resourceType is a method introduced in v1.8 that returns a string. It returns the request's resource type as it was perceived by the rendering engine. ResourceType will be one of the following: document, stylesheet, image, media, font, script, texttrack, xhr, fetch, eventsource, websocket, manifest, or other.

Request.response async method

Request.response is an async method introduced in v1.8 that returns null or Response. It returns the matching Response object, or null if the response was not received due to error.

Request.existingResponse method

Request.existingResponse is a method introduced in v1.59 that returns null or Response. It returns the Response object if the response has already been received, null otherwise. Unlike Request.response, this method does not wait for the response to arrive. It returns immediately with the response object if the response has been received, or null if the response has not been received yet.

Request.serviceWorker method

Request.serviceWorker is a method introduced in v1.24 available in JavaScript and Python that returns null or Worker. It returns the Service Worker that is performing the request. This method is Chromium only and is safe to call when using other browsers but will always be null. Requests originated in a Service Worker do not have Request.frame available.

Request.sizes async method

Request.sizes is an async method introduced in v1.15 that returns an Object (with alias RequestSizesResult in C# and Sizes in Java) with properties: requestBodySize (int) - size of the request body (POST data payload) in bytes, set to 0 if there was no body; requestHeadersSize (int) - total number of bytes from the start of the HTTP request message until and including the double CRLF before the body; responseBodySize (int) - size of the received response body (encoded) in bytes; responseHeadersSize (int) - total number of bytes from the start of the HTTP response message until and including the double CRLF before the body. The method returns resource size information for the given request.

Request.timing method

Request.timing is a method introduced in v1.8 that returns resource timing information for the given request. Most of the timing values become available upon the response, and responseEnd becomes available when the request finishes. Details follow the Resource Timing API specification on MDN.

Request.timing method example

Example in JavaScript: const requestFinishedPromise = page.waitForEvent('requestfinished'); await page.goto('http://example.com'); const request = await requestFinishedPromise; console.log(request.timing());

Request.url method

Request.url is a method introduced in v1.8 that returns a string. It returns the URL of the request.

Give your agent this brain