@browserless/cli
v14.0.0
Published
Command-line interface for headless browser automation. Take screenshots, generate PDFs, and extract content from websites.
Maintainers
Readme
@browserless/cli: CLI to interact with Browserless capabilities.
See the CLI section on our website for more information.
Install
Using npm:
npm install @browserless/cli -gAbout
This package provides a command-line interface for interacting with browserless capabilities directly from your terminal. It exposes the browserless binary that wraps the core browserless API into easy-to-use shell commands.
What this package does
The @browserless/cli package allows you to:
- Take screenshots from URLs with gradient backgrounds, browser overlays, and device emulation
- Record captures as video/audio using the
tabCaptureextension flow - Generate PDFs from web pages
- Extract content as HTML or plain text
- Run Lighthouse audits for performance analysis
- Analyze page weight (network requests, transfer size, resource size)
- Check URL status and response information (redirects, headers, status codes)
Available commands
| Command | Description |
|---------|-------------|
| capture <url> | Record a page and return video buffer (use --path to save file) |
| screenshot <url> | Capture a screenshot with optional overlay and background |
| pdf <url> | Generate a PDF document from a web page |
| html <url> | Serialize the page content to HTML |
| text <url> | Extract plain text content from the page |
| lighthouse <url> | Run a Google Lighthouse audit and output JSON report |
| page-weight <url> | Analyze network requests, resource sizes, and basic load timings |
| ping <url> | Get response info: status code, redirects, headers |
| status <url> | Get the HTTP status code |
| goto <url> | Navigate to a URL and return page/response info |
| exec <file> | Run a script file against a new page and print what it returns |
Exec examples
exec takes a file instead of a URL. The file exports a function (CommonJS
module.exports or ES module export default). The CLI opens a page and calls
the function with { page, browserless, opts }:
page: a new Puppeteer page in a fresh browser context.browserless: the browserless context, forbrowserless.goto(page, { url })and the rest of the API.opts: the command-line flags, plus the CLI defaultcodeScheme.--headlessand--verboseare consumed by the CLI and not passed.--timeoutis passed and also sets the browser timeout.
// title.js
module.exports = async ({ page, browserless, opts }) => {
await browserless.goto(page, { url: opts.url })
return { title: await page.title() }
}browserless exec title.js --url=https://example.comThe file path resolves from the current directory. A returned string is printed
as is and any other value as indented JSON. undefined and binary values
(buffers and typed arrays, such as the result of page.screenshot()) print
nothing, so write binary output to a file from the script. The file is checked
before the browser starts. A thrown error is
printed and the process exits with code 1.
Capture examples
# mp4 (default)
browserless capture https://example.com --path=./capture.mp4
# webm output type
browserless capture https://example.com --type=webm --path=./capture.webmNote: The
lighthousecommand requires an extra installation.Please make sure to install the standalone package by running: npm install -g @browserless/lighthouse
How it fits in the monorepo
This package depends on:
| Dependency | Purpose | |---------------------------|---------------------------------------------------------| | @browserless/capture | Extension-based tab capture for CLI video recording | | browserless | Core API for all browser automation operations | | @browserless/lighthouse | Lighthouse audit integration (used by lighthouse command) |
The CLI acts as a thin wrapper that parses command-line arguments, initializes a browserless instance, and delegates to the appropriate command handler.
License
@browserless/cli © Microlink, released under the MIT License. Authored and maintained by Microlink with help from contributors.
The logo has been designed by xinh studio.
microlink.io · GitHub microlinkhq · X @microlinkhq
