Skip to main content

Response

Struct Response 

Source
pub struct Response { /* private fields */ }
Expand description

Response from navigation operations.

Returned from page.goto(), page.reload(), page.go_back(), and similar navigation methods. Provides access to the HTTP response status, headers, and body.

See: https://playwright.dev/docs/api/class-response

Implementations§

Source§

impl Response

Source

pub fn url(&self) -> &str

Source

pub fn status(&self) -> u16

Source

pub fn status_text(&self) -> &str

Source

pub fn ok(&self) -> bool

Returns whether the response was successful (status 200-299).

See: https://playwright.dev/docs/api/class-response#response-ok

Source

pub fn headers(&self) -> &HashMap<String, String>

Returns the response headers as a HashMap.

Note: these are the headers from the protocol initializer. For the full raw headers (including duplicates), use headers_array() or all_headers().

See: https://playwright.dev/docs/api/class-response#response-headers

Source

pub fn request(&self) -> Option<Request>

Returns the Request that triggered this response.

Navigates the protocol object hierarchy: ResponseObject → parent (Request).

See: https://playwright.dev/docs/api/class-response#response-request

Source

pub fn frame(&self) -> Option<Frame>

Returns the Frame that initiated the request for this response.

Navigates the protocol object hierarchy: ResponseObject → Request → Frame.

See: https://playwright.dev/docs/api/class-response#response-frame

Source

pub async fn security_details(&self) -> Result<Option<SecurityDetails>>

Returns TLS/SSL security details for HTTPS connections, or None for HTTP.

See: https://playwright.dev/docs/api/class-response#response-security-details

Source

pub async fn server_addr(&self) -> Result<Option<RemoteAddr>>

Returns the server’s IP address and port, or None.

See: https://playwright.dev/docs/api/class-response#response-server-addr

Source

pub async fn finished(&self) -> Result<()>

Waits for this response to finish loading.

For responses obtained from navigation methods (goto, reload), the response is already finished when returned. For responses from on_response handlers, the body may still be loading.

See: https://playwright.dev/docs/api/class-response#response-finished

Source

pub async fn body(&self) -> Result<Vec<u8>>

Returns the response body as raw bytes.

Makes an RPC call to the Playwright server to fetch the response body.

§Errors

Returns an error if:

  • No backing protocol object is available (edge case)
  • The RPC call to the server fails
  • The base64 response cannot be decoded

See: https://playwright.dev/docs/api/class-response#response-body

Source

pub async fn text(&self) -> Result<String>

Returns the response body as a UTF-8 string.

Calls body() then converts bytes to a UTF-8 string.

§Errors

Returns an error if:

  • body() fails
  • The body is not valid UTF-8

See: https://playwright.dev/docs/api/class-response#response-text

Source

pub async fn json<T: DeserializeOwned>(&self) -> Result<T>

Parses the response body as JSON and deserializes it into type T.

Calls text() then uses serde_json to deserialize the body.

§Errors

Returns an error if:

  • text() fails
  • The body is not valid JSON or doesn’t match the expected type

See: https://playwright.dev/docs/api/class-response#response-json

Source

pub async fn headers_array(&self) -> Result<Vec<HeaderEntry>>

Returns all response headers as name-value pairs, preserving duplicates.

Makes an RPC call for "rawHeaders" which returns the complete header list.

§Errors

Returns an error if:

  • No backing protocol object is available (edge case)
  • The RPC call to the server fails

See: https://playwright.dev/docs/api/class-response#response-headers-array

Source

pub async fn all_headers(&self) -> Result<HashMap<String, String>>

Returns all response headers merged into a HashMap with lowercase keys.

When multiple headers have the same name, their values are joined with , . This matches the behavior of response.allHeaders() in other Playwright bindings.

§Errors

Returns an error if:

  • No backing protocol object is available (edge case)
  • The RPC call to the server fails

See: https://playwright.dev/docs/api/class-response#response-all-headers

Source

pub async fn header_value(&self, name: &str) -> Result<Option<String>>

Returns the value for a single response header, or None if not present.

The lookup is case-insensitive.

§Errors

Returns an error if:

  • No backing protocol object is available (edge case)
  • The RPC call to the server fails

See: https://playwright.dev/docs/api/class-response#response-header-value Returns the value for a single response header, or None if not present.

The lookup is case-insensitive. When multiple headers share the same name, their values are joined with , (matching Playwright’s behavior).

Uses the raw headers from the server for accurate results.

§Errors

Returns an error if the underlying headers_array() RPC call fails.

See: https://playwright.dev/docs/api/class-response#response-header-value

Trait Implementations§

Source§

impl Clone for Response

Source§

fn clone(&self) -> Response

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Response

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more