A GenServer owning a headless Chrome OS process and its CDP connections.
CDPEx.Browser launches Chrome (via CDPEx.Chrome), opens a browser-level
CDPEx.Connection, and creates pages on demand. It is the lifecycle owner:
- It traps exits and links every connection, so a page connection crash is isolated (the page is dropped; the browser and other pages survive), while a browser-connection or Chrome death stops the browser cleanly.
- For a launched browser,
terminate/2always runsCDPEx.Chrome.stop/1— the no-orphan guarantee. Because that relies onterminate/2, supervise a launched browser with a:shutdowntimeout, not:brutal_kill.
A browser started via CDPEx.connect/2 (connect-mode, chrome: nil) is the
exception: it never launched Chrome, so terminate/2 only closes the pages it
opened and never reaps the remote process — :brutal_kill is harmless there.
That target cleanup is best-effort: each Target.closeTarget is bounded by
the call timeout, and against a slow-but-alive remote with several open pages the
supervised shutdown budget can elapse before every tab is closed, leaving some
open on the remote Chrome (it never affects the local process, which holds no
Chrome to reap).
Most callers use the CDPEx facade rather than this module directly.
Summary
Functions
Closes a page opened with new_page/2.
Opens a new page (tab) and returns a CDPEx.Page handle.
Starts a browser. See CDPEx.Chrome for launch options.
Stops the browser, closing all pages.
Types
Functions
@spec close_page(GenServer.server(), CDPEx.Page.t()) :: :ok | {:error, :unknown_page}
Closes a page opened with new_page/2.
Returns {:error, :unknown_page} if the page does not belong to this browser
(a handle from a different browser, or one that was already closed).
@spec new_page( GenServer.server(), keyword() ) :: {:ok, CDPEx.Page.t()} | {:error, term()}
Opens a new page (tab) and returns a CDPEx.Page handle.
Options:
:transport—:dedicated(one WebSocket per page, strong crash isolation) or:session(multiplexed over the browser socket via a flattened CDP session — fewer sockets, but all session pages share the browser connection's fate: if it drops, they all go). A launched browser defaults to:dedicated; a connected browser (CDPEx.connect/2) defaults to:sessionand rejects:dedicatedwith{:error, {:unsupported_transport, :dedicated}}. Any other value returns{:error, {:invalid_transport, value}}.:prevent_alerts— inject no-opalert/confirm/prompt(defaulttrue)
@spec start_link(keyword()) :: GenServer.on_start()
Starts a browser. See CDPEx.Chrome for launch options.
Pass :owner (a pid) to set the process whose death triggers the browser's cleanup,
overriding the default (the calling process). CDPEx.Pool uses this when adopting a
browser it launched in a short-lived task.
@spec stop(GenServer.server()) :: :ok
Stops the browser, closing all pages.
A launched browser also kills its Chrome; a connected one (CDPEx.connect/2)
closes only the pages it opened and leaves the remote Chrome running.