Automator.Chromium (automator v0.1.3)

Copy Markdown View Source

Low-level Chromium process management.

Spawns a headless Chromium instance and provides the WebSocket debugger URL needed to connect via Automator.Client or Automator.Scraper.

Example

browser = Automator.Chromium.spawn()
# => %Automator.Chromium{chromium: #Port<...>, os_pid: 1234, port: 9222, ws_url: "ws://..."}

# Connect to the browser target
{:ok, client} = Automator.Client.start_link(browser.ws_url)
{:ok, result} = Automator.Client.send_command(client, "Browser.getVersion")

Automator.Chromium.kill(browser)

Browser Flags

Chromium is launched with these flags:

FlagValue
--headlessnew
--no-sandbox
--disable-gpu
--window-size1920,1080
--remote-debugging-portauto-detected (available TCP port)

When to Use

Use Chromium directly when you want to:

  • Connect multiple Automator.Client instances to the same browser
  • Manage the browser lifecycle independently of scraping sessions
  • Access the browser-level WebSocket target (not a page target)

For most use cases, prefer Automator.Scraper which handles this automatically.

Summary

Functions

Kills the Chromium process by OS PID.

Spawns a headless Chromium instance on an available port.

Types

t()

@type t() :: %Automator.Chromium{
  chromium: port(),
  os_pid: non_neg_integer(),
  port: :inet.port_number(),
  ws_url: String.t()
}

Functions

kill(chromium)

Kills the Chromium process by OS PID.

Example

browser = Automator.Chromium.spawn()
Automator.Chromium.kill(browser)

spawn()

Spawns a headless Chromium instance on an available port.

Launches Chromium with --headless=new, --no-sandbox, --disable-gpu, and --window-size=1920,1080. Finds an available TCP port automatically and sets --remote-debugging-port to it.

Returns an %Automator.Chromium{} struct with :chromium, :os_pid, :port, and :ws_url.

Example

browser = Automator.Chromium.spawn()
IO.puts(browser.ws_url)
# => "ws://localhost:9222/devtools/browser/..."