View Source Playwright.Request (playwright v1.44.0-alpha.4)

Playwright.Request represents a request for a network resource.

Whenever the page sends a request for a network resource, the following sequence of events are emitted by Playwright.Page:

  • Playwright.Page.on/3 for "request": emitted when the request is issued by the page.
  • Playwright.Page.on/3 for "response": emitted when/if the response status and headers are received for the request.
  • Playwright.Page.on/3 for "requestFinished": emitted when the response body is downloaded and the request is complete.

If the request fails at some point, instead of a "requestFinished" event (and possibly "response" as well), the Playwright.Page.on/3 for "requestFailed" is emitted.

NOTE

HTTP error responses, such as 404 or 503, are still successful responses from an HTTP stanpoint. So, such requests will complete with a "requestFinished" event.

If a request gets a "redirect" response, the request is successfully finished with the "requestFinished" event, and a new request is issued to the target redirected URL.

Summary

Types

t()

%Playwright.Request{}

Functions

Optional callback implementation for Playwright.SDK.ChannelOwner.init/2.

Types

@type t() :: %Playwright.Request{
  failure: term(),
  frame: term(),
  guid: term(),
  headers: term(),
  initializer: term(),
  is_navigation_request: term(),
  listeners: term(),
  method: term(),
  parent: term(),
  post_data: term(),
  post_data_buffer: term(),
  post_data_json: term(),
  redirected_from: term(),
  redirected_to: term(),
  resource_type: term(),
  session: term(),
  timing: term(),
  type: term(),
  url: term()
}

%Playwright.Request{}

Functions

Link to this function

init(owner, initializer)

View Source
@spec init(
  struct(),
  map()
) :: {atom(), struct()}

Optional callback implementation for Playwright.SDK.ChannelOwner.init/2.

If implemented, the callback will receive:

  1. The newly created "channel owner" struct.
  2. The :initializer received from the Playwright browser server.

The implementation has the option of "patching" the struct as stored in the catalog, and/or binding event handlers.

Example

def init(%{session: session} = owner, _initializer) do
  Channel.bind(session, {:guid, owner.guid}, :close, fn event ->
    Logger.warning("Closing #{inspect(event.target)}")
  end)

  {:ok, %{owner | version: "1.2.3"}}
end

Returns

  • {:ok, struct()}

Arguments

key/nametypedescription
ownerparamstruct()The newly created channel owner (resource).
initializerparamstruct()The initializer received from with the channel owner instance was derived.