Playwright.Response (Playwright v1.65.0-rc.3)

Copy Markdown View Source

Response class represents responses which are received by page.

Since Playwright 1.8.

The examples alias the modules they use (alias Playwright.{Locator, Page}).

Summary

Types

t()

A Response handle. Compare handles with ==, their fields are internal.

Functions

An object with all the response HTTP headers associated with this response.

Like all_headers/1, but returns the value and raises on error.

Returns the buffer with response body.

Like body/1, but returns the value and raises on error.

Waits for this response to finish, returns always nil.

Like finished/1, but returns the value and raises on error.

Returns the Frame that initiated this response.

Indicates whether this Response was fulfilled by a Service Worker's Fetch Handler (i.e. via FetchEvent.respondWith).

Returns the value of the header matching the name. The name is case-insensitive. If multiple headers have the same name (except set-cookie), they are returned as a list separated by ,. For set-cookie, the \n separator is used. If no headers are found, nil is returned.

Like header_value/2, but returns the value and raises on error.

Returns all values of the headers matching the name, for example set-cookie. The name is case-insensitive.

Like header_values/2, but returns the value and raises on error.

An object with the response HTTP headers. The header names are lower-cased. Note that this method does not return security-related headers, including cookie-related ones. You can use Playwright.Response.all_headers/1 for complete list of headers that include cookie information.

An array with all the response HTTP headers associated with this response. Unlike Playwright.Response.all_headers/1, header names are NOT lower-cased. Headers with multiple entries, such as Set-Cookie, appear in the array multiple times. Some browser network stacks combine multiple field values before reporting them, so separate entries are not always available.

Like headers_array/1, but returns the value and raises on error.

Returns the http version used by the response.

Like http_version/1, but returns the value and raises on error.

Returns the JSON representation of response body.

Like json/1, but returns the value and raises on error.

Contains a boolean stating whether the response was successful (status in the range 200-299) or not.

Returns the matching Request object.

Returns SSL and other security information.

Like security_details/1, but returns the value and raises on error.

Returns the IP address and port of the server.

Like server_addr/1, but returns the value and raises on error.

Contains the status code of the response (e.g., 200 for a success).

Contains the status text of the response (e.g. usually an "OK" for a success).

Returns the text representation of response body.

Like text/1, but returns the value and raises on error.

Contains the URL of the response.

Types

t()

@type t() :: %Playwright.Response{
  conn: term(),
  guid: term(),
  initializer: term(),
  table: term(),
  type: term()
}

A Response handle. Compare handles with ==, their fields are internal.

Functions

all_headers(response)

@spec all_headers(t()) ::
  {:ok, %{optional(String.t()) => String.t()}} | {:error, Playwright.error()}

An object with all the response HTTP headers associated with this response.

Since Playwright 1.15.

all_headers!(response)

@spec all_headers!(t()) :: %{optional(String.t()) => String.t()}

Like all_headers/1, but returns the value and raises on error.

body(response)

@spec body(t()) :: {:ok, binary()} | {:error, Playwright.error()}

Returns the buffer with response body.

Since Playwright 1.8.

body!(response)

@spec body!(t()) :: binary()

Like body/1, but returns the value and raises on error.

finished(response)

@spec finished(t()) :: {:ok, nil | Exception.t()} | {:error, Playwright.error()}

Waits for this response to finish, returns always nil.

Since Playwright 1.8.

finished!(response)

@spec finished!(t()) :: nil | Exception.t()

Like finished/1, but returns the value and raises on error.

frame(response)

@spec frame(t()) :: Playwright.Frame.t()

Returns the Frame that initiated this response.

Since Playwright 1.8.

from_service_worker(response)

@spec from_service_worker(t()) :: boolean()

Indicates whether this Response was fulfilled by a Service Worker's Fetch Handler (i.e. via FetchEvent.respondWith).

Since Playwright 1.23.

header_value(response, name)

@spec header_value(t(), String.t()) ::
  {:ok, nil | String.t()} | {:error, Playwright.error()}

Returns the value of the header matching the name. The name is case-insensitive. If multiple headers have the same name (except set-cookie), they are returned as a list separated by ,. For set-cookie, the \n separator is used. If no headers are found, nil is returned.

Since Playwright 1.15.

Arguments

  • name - Name of the header.

header_value!(response, name)

@spec header_value!(t(), String.t()) :: nil | String.t()

Like header_value/2, but returns the value and raises on error.

header_values(response, name)

@spec header_values(t(), String.t()) ::
  {:ok, [String.t()]} | {:error, Playwright.error()}

Returns all values of the headers matching the name, for example set-cookie. The name is case-insensitive.

Since Playwright 1.15.

Arguments

  • name - Name of the header.

header_values!(response, name)

@spec header_values!(t(), String.t()) :: [String.t()]

Like header_values/2, but returns the value and raises on error.

headers(response)

@spec headers(t()) :: %{optional(String.t()) => String.t()}

An object with the response HTTP headers. The header names are lower-cased. Note that this method does not return security-related headers, including cookie-related ones. You can use Playwright.Response.all_headers/1 for complete list of headers that include cookie information.

Since Playwright 1.8.

headers_array(response)

@spec headers_array(t()) ::
  {:ok, [%{name: String.t(), value: String.t()}]} | {:error, Playwright.error()}

An array with all the response HTTP headers associated with this response. Unlike Playwright.Response.all_headers/1, header names are NOT lower-cased. Headers with multiple entries, such as Set-Cookie, appear in the array multiple times. Some browser network stacks combine multiple field values before reporting them, so separate entries are not always available.

Since Playwright 1.15.

headers_array!(response)

@spec headers_array!(t()) :: [%{name: String.t(), value: String.t()}]

Like headers_array/1, but returns the value and raises on error.

http_version(response)

@spec http_version(t()) :: {:ok, String.t()} | {:error, Playwright.error()}

Returns the http version used by the response.

Since Playwright 1.59.

http_version!(response)

@spec http_version!(t()) :: String.t()

Like http_version/1, but returns the value and raises on error.

json(response)

@spec json(t()) :: {:ok, term()} | {:error, Playwright.error()}

Returns the JSON representation of response body.

This method will fail if the response body is not parsable via JSON.parse.

Since Playwright 1.8.

json!(response)

@spec json!(t()) :: term()

Like json/1, but returns the value and raises on error.

ok(response)

@spec ok(t()) :: boolean()

Contains a boolean stating whether the response was successful (status in the range 200-299) or not.

Since Playwright 1.8.

request(response)

@spec request(t()) :: Playwright.Request.t()

Returns the matching Request object.

Since Playwright 1.8.

security_details(response)

@spec security_details(t()) ::
  {:ok,
   nil
   | %{
       optional(:issuer) => String.t(),
       optional(:protocol) => String.t(),
       optional(:subjectName) => String.t(),
       optional(:validFrom) => number(),
       optional(:validTo) => number()
     }}
  | {:error, Playwright.error()}

Returns SSL and other security information.

Since Playwright 1.13.

security_details!(response)

@spec security_details!(t()) ::
  nil
  | %{
      optional(:issuer) => String.t(),
      optional(:protocol) => String.t(),
      optional(:subjectName) => String.t(),
      optional(:validFrom) => number(),
      optional(:validTo) => number()
    }

Like security_details/1, but returns the value and raises on error.

server_addr(response)

@spec server_addr(t()) ::
  {:ok, nil | %{ipAddress: String.t(), port: integer()}}
  | {:error, Playwright.error()}

Returns the IP address and port of the server.

Since Playwright 1.13.

server_addr!(response)

@spec server_addr!(t()) :: nil | %{ipAddress: String.t(), port: integer()}

Like server_addr/1, but returns the value and raises on error.

status(response)

@spec status(t()) :: integer()

Contains the status code of the response (e.g., 200 for a success).

Since Playwright 1.8.

status_text(response)

@spec status_text(t()) :: String.t()

Contains the status text of the response (e.g. usually an "OK" for a success).

Since Playwright 1.8.

text(response)

@spec text(t()) :: {:ok, String.t()} | {:error, Playwright.error()}

Returns the text representation of response body.

Since Playwright 1.8.

text!(response)

@spec text!(t()) :: String.t()

Like text/1, but returns the value and raises on error.

url(response)

@spec url(t()) :: String.t()

Contains the URL of the response.

Since Playwright 1.8.