Skip to content

CLI and CDP examples

Terminal window
brimp doctor

Successful output is JSON suitable for scripts:

{"javascriptCore":"ok","libcurlImpersonate":"ok","profile":"chrome150"}

brimp eval prints the evaluated JSON value to standard output and diagnostics to standard error:

Terminal window
brimp eval https://example.com \
--js '({title: document.title, links: document.querySelectorAll("a").length})'

Set a navigation timeout in milliseconds when the 30-second default is not appropriate:

Terminal window
brimp eval https://example.com \
--timeout-ms 10000 \
--js 'document.body.textContent.trim()'
Terminal window
brimp eval https://example.com \
--persona persona/example.json \
--js '({ua: navigator.userAgent, platform: navigator.platform})'
Terminal window
brimp screenshot https://example.com \
--output example.png \
--full-page

Brimp refuses to replace an existing file unless --overwrite is explicit.

Start the server on its loopback default:

Terminal window
brimp cdp

The first output line is the browser WebSocket endpoint. Puppeteer can discover it through the HTTP 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 server to a network unless you intend to give every reachable client control of the browser. Non-loopback binds require --allow-non-loopback and print a security warning.

See the CLI API and CDP API for exhaustive support.