pub struct Response {
pub url: String,
pub status: u16,
pub status_text: String,
pub ok: bool,
pub headers: HashMap<String, String>,
/* 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.
Fields§
§url: StringURL of the response
status: u16HTTP status code
status_text: StringHTTP status text
ok: boolWhether the response was successful (status 200-299)
headers: HashMap<String, String>Response headers (from initializer, may not include all raw headers)
Implementations§
Source§impl Response
impl Response
Sourcepub fn url(&self) -> &str
pub fn url(&self) -> &str
Returns the URL of the response.
See: https://playwright.dev/docs/api/class-response#response-url
Sourcepub fn status(&self) -> u16
pub fn status(&self) -> u16
Returns the HTTP status code.
See: https://playwright.dev/docs/api/class-response#response-status
Sourcepub fn status_text(&self) -> &str
pub fn status_text(&self) -> &str
Returns the HTTP status text.
See: https://playwright.dev/docs/api/class-response#response-status-text
Sourcepub fn ok(&self) -> bool
pub fn ok(&self) -> bool
Returns whether the response was successful (status 200-299).
See: https://playwright.dev/docs/api/class-response#response-ok
Sourcepub fn headers(&self) -> &HashMap<String, String>
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
Sourcepub async fn body(&self) -> Result<Vec<u8>>
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
Sourcepub async fn text(&self) -> Result<String>
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
Sourcepub async fn json<T: DeserializeOwned>(&self) -> Result<T>
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
Sourcepub async fn headers_array(&self) -> Result<Vec<HeaderEntry>>
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
Sourcepub async fn all_headers(&self) -> Result<HashMap<String, String>>
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
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 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