Skip to content

CLI and CDP examples

CLI browser commands currently require macOS and a child worker. Set BRIMP_WORKER_PATH to the lite worker executable or a WebKit worker bundle, or pass --worker-path PATH. Build both with cargo build -p brimp-controller -p brimp-lite-worker.

Terminal window
brimp doctor

Successful output is JSON suitable for scripts:

{"javascriptCore":"ok","libcurlImpersonate":"ok","worker":"lite-worker"}

Use the fetch guide to save HTML, extract Markdown and metadata, evaluate JavaScript, configure personas, and capture screenshots. Use the crawl guide to follow links within a defined scope and save pages with a manifest.

Terminal window
brimp serve \
--worker-path /path/to/lite-worker \
--headless --window-size=1280,720 --port=9222

Playwright attaches through its public connectOverCDP() API:

import { chromium } from 'playwright-core'
const browser = await chromium.connectOverCDP('http://127.0.0.1:9222')
try {
const context = browser.contexts()[0] ?? await browser.newContext()
const page = await context.newPage()
await page.goto('https://example.com', { waitUntil: 'load' })
console.log(await page.evaluate(() => document.title))
await page.close()
} finally {
await browser.close()
}

Use playwright-core, not a Playwright browser download: Brimp is the browser process being controlled.

Puppeteer connects to the controller’s HTTP discovery endpoint:

const fs = require('node:fs/promises')
const puppeteer = require('puppeteer-core')
const browser = await puppeteer.connect({
browserURL: 'http://127.0.0.1:9222',
})
const [page] = await browser.pages()
await page.goto('https://example.com')
const result = await page.evaluate(() => ({
title: document.title,
answer: 6 * 7,
}))
const png = await page.screenshot()
console.log(result)
await fs.writeFile('example.png', png)
await browser.disconnect()

Do not expose the controller to a network unless you intend to give every reachable client control of the browser.

See the CLI API and CDP API for exhaustive support.