Tungsten v0.1.0 Tungsten.CDP.Fetch View Source

Fetch

A domain for letting clients substitute browser's network layer with client code.

Link to this section Summary

Link to this section Types

Link to this type

cdp_auth_challenge_response_type() View Source
cdp_auth_challenge_response_type() :: %{
  :response => :provide_credentials | :cancel_auth | :default,
  optional(:username) => String.t(),
  optional(:password) => String.t()
}

Fetch.AuthChallengeResponse

Response to an AuthChallenge.

Link to this type

cdp_auth_challenge_type() View Source
cdp_auth_challenge_type() :: %{
  optional(:source) => :proxy | :server,
  :origin => String.t(),
  :scheme => String.t(),
  :realm => String.t()
}

Fetch.AuthChallenge

Authorization challenge for HTTP status code 401 or 407.

Link to this type

cdp_header_entry_type() View Source
cdp_header_entry_type() :: %{name: String.t(), value: String.t()}

Fetch.HeaderEntry

Response HTTP header entry

Link to this type

cdp_request_id_type() View Source
cdp_request_id_type() :: String.t()

Fetch.RequestId

Unique request identifier.

Link to this type

cdp_request_pattern_type() View Source
cdp_request_pattern_type() :: %{
  optional(:url_pattern) => String.t(),
  optional(:resource_type) => Tungsten.CDP.Network.cdp_resource_type_type(),
  optional(:request_stage) => cdp_request_stage_type()
}

Fetch.RequestPattern

This type has no documentation

Link to this type

cdp_request_stage_type() View Source
cdp_request_stage_type() :: :response | :request

Fetch.RequestStage

Stages of the request to handle. Request will intercept before the request is sent. Response will intercept after the response is received (but before response body is received.

Link to this section Functions

Link to this function

continue_request(session, parameters, options \\ []) View Source
continue_request(
  GenServer.server(),
  %{
    :request_id => cdp_request_id_type(),
    optional(:url) => String.t(),
    optional(:method) => String.t(),
    optional(:post_data) => String.t(),
    optional(:headers) => [cdp_header_entry_type()]
  },
  Tungsten.Connection.exec_options()
) :: {:ok, map()} | {:error, term()}

Fetch.continueRequest

Continues the request, optionally modifying some of its parameters.

Link to this function

continue_with_auth(session, parameters, options \\ []) View Source
continue_with_auth(
  GenServer.server(),
  %{
    request_id: cdp_request_id_type(),
    auth_challenge_response: cdp_auth_challenge_response_type()
  },
  Tungsten.Connection.exec_options()
) :: {:ok, map()} | {:error, term()}

Fetch.continueWithAuth

Continues a request supplying authChallengeResponse following authRequired event.

Link to this function

disable(session, parameters \\ %{}, options \\ []) View Source
disable(GenServer.server(), map(), Tungsten.Connection.exec_options()) ::
  {:ok, map()} | {:error, term()}

Fetch.disable

Disables the fetch domain.

Link to this function

enable(session, parameters \\ %{}, options \\ []) View Source
enable(
  GenServer.server(),
  %{
    optional(:patterns) => [cdp_request_pattern_type()],
    optional(:handle_auth_requests) => boolean()
  },
  Tungsten.Connection.exec_options()
) :: {:ok, map()} | {:error, term()}

Fetch.enable

Enables issuing of requestPaused events. A request will be paused until client calls one of failRequest, fulfillRequest or continueRequest/continueWithAuth.

Link to this function

fail_request(session, parameters, options \\ []) View Source
fail_request(
  GenServer.server(),
  %{
    request_id: cdp_request_id_type(),
    error_reason: Tungsten.CDP.Network.cdp_error_reason_type()
  },
  Tungsten.Connection.exec_options()
) :: {:ok, map()} | {:error, term()}

Fetch.failRequest

Causes the request to fail with specified reason.

Link to this function

fulfill_request(session, parameters, options \\ []) View Source
fulfill_request(
  GenServer.server(),
  %{
    :request_id => cdp_request_id_type(),
    :response_code => integer(),
    :response_headers => [cdp_header_entry_type()],
    optional(:body) => String.t(),
    optional(:response_phrase) => String.t()
  },
  Tungsten.Connection.exec_options()
) :: {:ok, map()} | {:error, term()}

Fetch.fulfillRequest

Provides response to the request.

Link to this function

get_response_body(session, parameters, options \\ []) View Source
get_response_body(
  GenServer.server(),
  %{request_id: cdp_request_id_type()},
  Tungsten.Connection.exec_options()
) :: {:ok, %{body: String.t(), base64_encoded: boolean()}} | {:error, term()}

Fetch.getResponseBody

Causes the body of the response to be received from the server and returned as a single string. May only be issued for a request that is paused in the Response stage and is mutually exclusive with takeResponseBodyForInterceptionAsStream. Calling other methods that affect the request or disabling fetch domain before body is received results in an undefined behavior.

Link to this function

take_response_body_as_stream(session, parameters, options \\ []) View Source
take_response_body_as_stream(
  GenServer.server(),
  %{request_id: cdp_request_id_type()},
  Tungsten.Connection.exec_options()
) ::
  {:ok, %{stream: Tungsten.CDP.IO.cdp_stream_handle_type()}} | {:error, term()}

Fetch.takeResponseBodyAsStream

Returns a handle to the stream representing the response body. The request must be paused in the HeadersReceived stage. Note that after this command the request can't be continued as is -- client either needs to cancel it or to provide the response body. The stream only supports sequential read, IO.read will fail if the position is specified. This method is mutually exclusive with getResponseBody. Calling other methods that affect the request or disabling fetch domain before body is received results in an undefined behavior.