CDPEx.Proxy (CDPEx v0.7.0)

Copy Markdown View Source

Parses the :proxy launch option into a Chrome --proxy-server flag plus, when the proxy is authenticated, the credentials CDPEx.Browser arms on each page.

Accepts either a URL string or a keyword list / map:

"http://user:pass@host:8080"
[server: "host:8080", scheme: "http", username: "user", password: "pass"]

In the URL form, credentials with reserved characters must be percent-encoded (e.g. p@ssp%40ss); they are decoded back on parse. The keyword form takes credentials verbatim, so prefer it when a password contains reserved characters.

See the :proxy option on CDPEx.launch/1.

Summary

Types

t()

A parsed proxy: the scheme://host:port value for Chrome's --proxy-server (userinfo stripped), plus optional credentials (nil for an open proxy).

Functions

Credentials (%{username, password}) when the proxy needs auth, else nil.

Parses a :proxy value into {:ok, t} or {:error, {:invalid_proxy, reason}}.

The --proxy-server=… Chrome flag for a parsed proxy.

Types

t()

@type t() :: %{
  server: String.t(),
  username: String.t() | nil,
  password: String.t() | nil
}

A parsed proxy: the scheme://host:port value for Chrome's --proxy-server (userinfo stripped), plus optional credentials (nil for an open proxy).

Functions

credentials(arg1)

@spec credentials(t()) :: %{username: String.t(), password: String.t()} | nil

Credentials (%{username, password}) when the proxy needs auth, else nil.

Both parts must be present and non-empty; a missing or empty half is treated as no auth (the proxy is used unauthenticated).

parse(url)

@spec parse(term()) :: {:ok, t()} | {:error, {:invalid_proxy, term()}}

Parses a :proxy value into {:ok, t} or {:error, {:invalid_proxy, reason}}.

to_arg(map)

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

The --proxy-server=… Chrome flag for a parsed proxy.