Rover.Browser (Rover v0.1.0)

Copy Markdown View Source

A long-lived browser session.

Each Rover.Browser owns one rover_runtime OS process. The subprocess in turn owns exactly one Servo instance and one WebView — so one browser = one isolated rendering context with its own proxy, cookies, and network state.

Call start_link/1 to open a browser, then drive it with the functions in the top-level Rover module:

{:ok, browser} = Rover.Browser.start_link(proxy: "http://proxy:8080")
:ok = Rover.navigate(browser, "https://example.com")
{:ok, html} = Rover.content(browser)
Rover.stop(browser)

The process is meant to be added to your own supervisor. If you just need a page's rendered HTML, reach for Rover.fetch/2 — it spins a browser up, runs your operation, and tears it down.

Lifecycle

  • start_link/1 blocks until the runtime reports Hello and accepts its Init. A failed init returns {:error, %Rover.Error{}} — the GenServer does not start.
  • If the runtime subprocess crashes, the GenServer exits with reason {:port_died, details} and pending callers receive {:error, %Rover.Error{reason: :port_died}}. Use a supervisor to restart the browser.

Summary

Functions

Returns a specification to start this module under a supervisor.

Start a browser linked to the caller.

Shut the browser down cleanly.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

start_link(opts \\ [])

@spec start_link(keyword()) :: GenServer.on_start()

Start a browser linked to the caller.

Options

  • :proxy — HTTP/HTTPS proxy URI ("http://host:port" or with "http://user:pass@host:port"). Baked into the engine for the lifetime of this browser. Default: direct (no proxy).
  • :user_agent — custom User-Agent string. Default: Servo's default.
  • :viewport{width, height} in CSS pixels. Default: {1280, 720}.
  • :name — standard GenServer registration name.
  • :runtime_path — override the path to the runtime binary; useful for tests. Default: resolved by Rover.Runtime.
  • :init_timeout — how long to wait for the runtime to accept Init. Default: 30s.

stop(server, timeout \\ 5000)

@spec stop(GenServer.server(), timeout()) :: :ok

Shut the browser down cleanly.

Sends Shutdown to the runtime and waits for it to exit, then terminates the GenServer. Returns :ok even if the runtime was already gone.