pub struct Request { /* private fields */ }Expand description
Request represents an HTTP request during navigation.
Request objects are created by the server during navigation operations. They are parents to Response objects.
Implementations§
Source§impl Request
impl Request
Sourcepub fn new(
parent: Arc<dyn ChannelOwner>,
type_name: String,
guid: Arc<str>,
initializer: Value,
) -> Result<Self>
pub fn new( parent: Arc<dyn ChannelOwner>, type_name: String, guid: Arc<str>, initializer: Value, ) -> Result<Self>
Creates a new Request from protocol initialization
This is called by the object factory when the server sends a __create__ message
for a Request object.
Sourcepub fn frame(&self) -> Option<Frame>
pub fn frame(&self) -> Option<Frame>
Returns the Frame that initiated this request.
The frame is resolved from the frame GUID in the protocol initializer data.
See: https://playwright.dev/docs/api/class-request#request-frame
Sourcepub fn redirected_from(&self) -> Option<Request>
pub fn redirected_from(&self) -> Option<Request>
Returns the request that redirected to this one, or None.
When the server responds with a redirect, Playwright creates a new Request
for the redirect target. The new request’s redirected_from points back to
the original request.
See: https://playwright.dev/docs/api/class-request#request-redirected-from
Sourcepub fn redirected_to(&self) -> Option<Request>
pub fn redirected_to(&self) -> Option<Request>
Returns the request that this one redirected to, or None.
This is the inverse of redirected_from(): if request A redirected to
request B, then A.redirected_to() returns B.
See: https://playwright.dev/docs/api/class-request#request-redirected-to
Sourcepub async fn response(&self) -> Result<Option<Response>>
pub async fn response(&self) -> Result<Option<Response>>
Returns the Response for this request.
Sends a "response" RPC call to the Playwright server.
Returns None if the request has not received a response (e.g., it failed).
See: https://playwright.dev/docs/api/class-request#request-response
Sourcepub async fn sizes(&self) -> Result<RequestSizes>
pub async fn sizes(&self) -> Result<RequestSizes>
Returns resource size information for this request.
Internally fetches the associated Response (via RPC) and calls sizes()
on the response’s channel.
See: https://playwright.dev/docs/api/class-request#request-sizes
Sourcepub fn url(&self) -> &str
pub fn url(&self) -> &str
Returns the URL of the request.
See: https://playwright.dev/docs/api/class-request#request-url
Sourcepub fn method(&self) -> &str
pub fn method(&self) -> &str
Returns the HTTP method of the request (GET, POST, etc.).
See: https://playwright.dev/docs/api/class-request#request-method
Sourcepub fn resource_type(&self) -> &str
pub fn resource_type(&self) -> &str
Returns the resource type of the request (e.g., “document”, “stylesheet”, “image”, “fetch”, etc.).
See: https://playwright.dev/docs/api/class-request#request-resource-type
Check if this request is for a navigation (main document).
A navigation request is when the request is for the main frame’s document. This is used to distinguish between main document loads and subresource loads.
See: https://playwright.dev/docs/api/class-request#request-is-navigation-request
Sourcepub fn headers(&self) -> HashMap<String, String>
pub fn headers(&self) -> HashMap<String, String>
Returns the request headers as a HashMap.
The headers are read from the protocol initializer data. The format in the
protocol is a list of {name, value} objects which are merged into a
HashMap<String, String>. If duplicate header names exist, the last
value wins.
For the full set of raw headers (including duplicates), use
headers_array() or all_headers().
See: https://playwright.dev/docs/api/class-request#request-headers
Sourcepub fn post_data_buffer(&self) -> Option<Vec<u8>>
pub fn post_data_buffer(&self) -> Option<Vec<u8>>
Returns the request body (POST data) as bytes, or None if there is no body.
The Playwright protocol sends postData as a base64-encoded string.
This method decodes it to raw bytes.
This is a local read and does not require an RPC call.
See: https://playwright.dev/docs/api/class-request#request-post-data-buffer
Sourcepub fn post_data(&self) -> Option<String>
pub fn post_data(&self) -> Option<String>
Returns the request body (POST data) as a UTF-8 string, or None if there is no body.
The Playwright protocol sends postData as a base64-encoded string.
This method decodes the base64 and then converts the bytes to a UTF-8 string.
This is a local read and does not require an RPC call.
See: https://playwright.dev/docs/api/class-request#request-post-data
Sourcepub fn post_data_json<T: DeserializeOwned>(&self) -> Option<Result<T>>
pub fn post_data_json<T: DeserializeOwned>(&self) -> Option<Result<T>>
Parses the POST data as JSON and deserializes into the target type T.
Returns None if the request has no POST data, or Some(Err(...)) if the
JSON parsing fails.
See: https://playwright.dev/docs/api/class-request#request-post-data-json
Sourcepub fn failure(&self) -> Option<String>
pub fn failure(&self) -> Option<String>
Returns the error text if the request failed, or None for successful requests.
The failure text is set when the requestFailed browser event fires for this
request. Use page.on_request_failed() to capture failed requests and then
call this method to get the error reason.
See: https://playwright.dev/docs/api/class-request#request-failure
Sourcepub async fn headers_array(&self) -> Result<Vec<HeaderEntry>>
pub async fn headers_array(&self) -> Result<Vec<HeaderEntry>>
Returns all request headers as name-value pairs, preserving duplicates.
Sends a "rawRequestHeaders" RPC call to the Playwright server which returns
the complete list of headers as sent over the wire, including headers added by
the browser (e.g., accept-encoding, accept-language).
§Errors
Returns an error if the RPC call to the server fails.
See: https://playwright.dev/docs/api/class-request#request-headers-array
Sourcepub async fn all_headers(&self) -> Result<HashMap<String, String>>
pub async fn all_headers(&self) -> Result<HashMap<String, String>>
Returns all request headers as a HashMap<String, String> with lowercased keys.
When multiple headers have the same name, their values are joined with \n
(matching Playwright’s behavior).
Sends a "rawRequestHeaders" RPC call to the Playwright server.
§Errors
Returns an error if the RPC call to the server fails.
See: https://playwright.dev/docs/api/class-request#request-all-headers
Sourcepub async fn header_value(&self, name: &str) -> Result<Option<String>>
pub async fn header_value(&self, name: &str) -> Result<Option<String>>
Returns the value of the specified header (case-insensitive), or None if not found.
Uses all_headers() internally, so it sends a
"rawRequestHeaders" RPC call to the Playwright server.
§Errors
Returns an error if the RPC call to the server fails.
See: https://playwright.dev/docs/api/class-request#request-header-value
Sourcepub async fn timing(&self) -> Result<ResourceTiming>
pub async fn timing(&self) -> Result<ResourceTiming>
Returns timing information for the request.
The timing data is sourced from the associated Response’s initializer when the
requestFinished event fires. This method should be called from within a
page.on_request_finished() handler or after it has fired.
Fields use -1 to indicate that a timing phase was not reached or is
unavailable for a given request.
§Errors
Returns an error if timing data is not yet available (e.g., called before
requestFinished fires, or for a request that has not completed successfully).
See: https://playwright.dev/docs/api/class-request#request-timing