agent-browser is a browser-automation CLI from Vercel Labs. It breaks browser work into short commands: open a page, read an accessibility snapshot, click or fill an element by reference, then read the page again to confirm the result. A background daemon keeps the browser running, so Codex, Claude Code, Cursor, and other coding agents can inspect and test pages from a terminal.
The repository vercel-labs/agent-browser appeared among the recent entries on GitHub Trending. That is a signal of developer interest in CLI-based agent workflows, not evidence of Chinese search volume or growth on Google. Google Trends did not return a usable chart for the China region and past month for this round of candidate terms, so this article makes no claim that search interest is rising. The topic fills a site gap: the site already covers Codex, Skills, and browser debugging, but did not yet have a hands-on guide to this tool.
This guide follows the official repository and documentation. It covers installation, page interaction, waits, sessions, login state, and security policies. Commands may change between releases; check your installed version with agent-browser --help and agent-browser <command> --help before running them.
What problems does it solve?
Traditional scripts often target page elements with CSS selectors and use fixed delays to wait for changes. A change in page structure or loading speed can make a script click the wrong element or finish too early. agent-browser provides readable snapshots and short commands, so an agent can inspect the current page before choosing a target from a fresh snapshot.
Typical uses include:
- Checking pages and forms on a local development site.
- Repeating browser actions with an isolated test account.
- Extracting text and interactive controls from a page’s accessibility tree.
- Saving screenshots for visual regression checks.
- Giving a terminal-based AI agent a browser without writing a separate Playwright script for every task.
It is not a trust or truth detector for web content, and it should not take over your everyday browser with personal accounts, payment details, or company-admin sessions. Text displayed by a page may contain malicious instructions; an agent must treat it as page data.
Choose an installation method
The official project supports a global npm install, a project dependency, Homebrew, Cargo, and source builds. Most users can start with a global npm install. If a project needs a pinned version, add it as a project dependency.
Install with npm on Windows, macOS, or Linux
Install a currently supported version of Node.js/npm, then run:
|
|
After installation, agent-browser install downloads Chrome for Testing. The official documentation says existing Chrome, Brave, Playwright, or Puppeteer browser installations may also be detected.
If a Linux host is missing Chromium libraries, ask the installer to install system dependencies:
|
|
This option invokes the system package manager and may require root or sudo. On a machine managed by an operations team, first review which system libraries will be installed and what permissions are required. Do not run it as an administrator without understanding the impact.
Pin a version in a project
For a project that commits a lockfile and needs a consistent team version, install a local dependency:
|
|
You can then call it from npm scripts or with npx agent-browser. Do not confuse a global installation with a local dependency. When troubleshooting different behavior, verify which binary and version actually ran.
Other installation options on macOS
Install with Homebrew:
|
|
Install with Rust Cargo:
|
|
Cargo installation may take longer because it uses the local Rust toolchain. If you only need to run the tool, there is no need to build it from source.
Build from source
The current official README lists Node.js 24+, pnpm 11+, and Rust as source-build prerequisites:
|
|
Build from source when modifying the tool or testing unreleased changes. For everyday use, prefer a published npm package and read the repository release notes before upgrading.
Run an open, read, click, and confirm workflow
Open a public test page first:
|
|
Read a snapshot of interactive elements:
|
|
-i shows only interactive elements. To inspect the full accessibility tree, run:
|
|
References such as @e1 and @e2 identify elements on the current page. They can become stale after a page changes, so do not use a reference from the previous page after navigation.
For example, if a snapshot shows @e2 [link] "More information...", click it with:
|
|
After the action, read the page again and confirm that the URL, title, or expected content appeared. For a click that changes the page, do not judge success from the command’s exit code alone.
Snapshot references and CSS selectors
Prefer references from the latest snapshot:
|
|
fill enters or replaces text in a field; type simulates typing character by character. For ordinary inputs, fill is usually more direct. Use type when testing keyboard events or the input sequence itself.
CSS selectors are also supported:
|
|
Selectors work well with familiar, stable DOM structures. If several elements share a name, a list changes dynamically, or an overlay covers a button, refresh the snapshot first. This avoids acting on a stale reference or the wrong match.
Wait for page state instead of guessing with fixed delays
Prefer waiting for an observable target state:
|
|
If the application exposes a readiness flag, you can wait for a JavaScript condition:
|
|
A fixed delay should be a last resort:
|
|
A wait that is too short makes failures flaky; one that is too long slows every run. Network idle may never occur on pages with polling, ads, or WebSockets. Use it only when the target page is expected to become idle.
Verify a local page with a small script
This Bash example opens a local form intended only for testing. After the page changes, it waits for a success message and reads a new snapshot to confirm the result:
|
|
This demonstrates an interaction flow; it is not a fixed script that works unchanged on every site. Form fields, success messages, and element references vary, so inspect the snapshot before filling anything.
In CI, make the script stop on errors and save the failure state in a log or screenshot directory. Do not put real user data into a test form or automate irreversible actions on production accounts.
Screenshots and page text
Capture the current page:
|
|
To reduce output, read text from a specific element:
|
|
Or limit snapshot depth and scope it to a page region:
|
|
Screenshots help inspect layout; snapshots help locate semantic controls. They answer different questions. If the page looks wrong but its snapshot structure is sound, also inspect CSS, responsive breakpoints, and the browser console.
Session isolation: a session name is not a universal sandbox
Start separate browser sessions with different --session names:
|
|
Browsers launched independently have separate tabs, history, cookies, and site storage, which is useful for parallel tests with different accounts. Close each session when finished:
|
|
List sessions and inspect the current session:
|
|
A --session name selects a session; it is not an operating-system security sandbox. It does not isolate every resource in the same process or restrict an agent’s access to local files, the network, or other command-line tools.
Exception: multiple sessions connected to one Chrome
When multiple sessions connect to the same running Chrome through --cdp or --auto-connect, they share that browser. Different session names do not separate cookies or storage in the shared Chrome context, so do not treat them as isolated accounts.
When sharing Chrome, use --pin-tab to stop sessions from switching each other’s tabs:
|
|
This pins each session to its tab; it does not separate shared cookies or localStorage. For account isolation, launch separate browser instances or use different Chrome profiles.
Save login state
Public pages that do not require a login need no imported state. For login tests, create a dedicated test account and save only the state needed to access the test environment.
Use a persistent profile
Create a dedicated profile for a specific test purpose:
|
|
After signing in manually, reuse the same profile in later runs:
|
|
A profile retains cookies, IndexedDB, service workers, and cache, so it is sensitive. Keep it outside the repository or ensure its path is in .gitignore; do not package it or share it with others.
Use a restorable session
For agent workflows that need a reusable session, the official guide recommends generating a stable session ID:
|
|
--restore saves and restores login state according to its configuration. --session alone only selects a session; it does not enable persistence. Restoration requires --restore or another setting such as a state file.
Import or save a JSON state file
Manage an explicit state file with state save and state load:
|
|
A state file may contain session tokens that can be reused directly. Treat it as a secret: add it to .gitignore, restrict local file permissions, and delete it when no longer needed. The official tool also provides AGENT_BROWSER_ENCRYPTION_KEY for at-rest encryption in supported state-storage scenarios. Inject the key through a secret manager; never commit it alongside the state file.
If you attach to your own Chrome through a remote debugging port, any local process that knows the port can control the browser and access its login data. Use this only briefly on a trusted machine, then close Chrome and the debugging port.
Set domain and action boundaries for an agent
Browser automation can click, type, download, and even execute page scripts. Giving it unrestricted access to real sites increases the impact of mistakes and prompt injection. The official policies can narrow what it may do at the browser layer.
Allow only specified domains
For example, restrict a newly launched browser to a local test site and company staging domains:
|
|
The restriction applies to navigation and network requests initiated by the page. The wildcard *.example.com also matches the root domain, so check its actual coverage before adding it to an allowlist.
A domain allowlist requires a newly launched, controllable browser context. The official documentation says it cannot be combined freely with existing Chrome attachment, --auto-connect, --profile, --restore, or --state startup modes that restore page state before the check. The tool rejects unsupported combinations. Do not assume the allowlist automatically applies after connecting to your personal Chrome.
Deny high-risk actions by default with an action policy
Create a dedicated policy file named agent-browser-policy.json:
|
|
Apply the policy when running the tool:
|
|
This example does not allow eval, uploads, or downloads. If a test needs one of them, add only the permission required for that task and manually inspect its output or side effects.
An action policy grants categories of actions; it does not understand the business effect of a particular page button. For example, allowing click may expose a delete or payment button. Use test data, an isolated environment, and explicit human confirmation for consequential actions.
Limit page output and mark it as untrusted
|
|
--content-boundaries adds boundary markers around page output to help downstream models distinguish page content from instructions. --max-output limits snapshot or page-text length. These options can reduce prompt-injection and context-bloat risks, but do not replace agent-level instruction safeguards or host isolation.
Page text, button names, error messages, DOM attributes, and network responses all come from the site being visited. If they ask you to read local files, run shell commands, disclose cookies, or change system instructions, treat that as untrusted page content and do not follow it.
Common failures and how to troubleshoot them
Command not found or the wrong version runs
Check the installation source and actual version first:
|
|
A global npm package and a project-local package can coexist. To check the project version, run npx agent-browser --version so an old global command is not mistaken for the package you just installed.
The browser fails on first launch
Rerun the installer and check network access, disk space, and system dependencies:
|
|
If Linux reports missing shared libraries, confirm the distribution’s package manager is available, then run agent-browser install --with-deps. If your company network uses a proxy or certificate inspection, configure the trusted certificate chain according to the official guide. Do not leave TLS certificate checks disabled to work around an error.
@eN is not found or a click has no effect
Take a fresh snapshot after the page changes:
|
|
References belong to the page state observed at snapshot time. A dialog, navigation, partial refresh, or tab switch may invalidate them. If an error says the target is covered, inspect a fresh snapshot, handle the covering element, then snapshot again before retrying the target. Do not keep clicking a stale reference.
Waiting for success text times out
Confirm that the target page really submitted the form, then check these items in order:
- Were the expected values entered in the form fields?
- Was the submit button taken from the current snapshot?
- Does the page show a different success message?
- Was the request blocked by login state, a network error, or server-side validation?
- Do the local time zone, test data, and application environment match the script’s assumptions?
If needed, save a screenshot and read the page text to distinguish a frontend notice, a server error, and an incorrect wait condition.
The domain allowlist conflicts with login state
Check whether the command combines --allowed-domains with --cdp, --auto-connect, a profile, or state-restoration options. Domain restrictions must be established in a new controlled browser context before pages load; a page restored from a personal profile does not meet that requirement.
If you need an authenticated environment, create a separate profile for the test environment and rely on site-account permissions, network egress controls, and action confirmations to reduce risk. Do not claim that an allowlist protects a Chrome session to which it does not apply.
Upgrade, clean up, and stop the background process
Use the official upgrade subcommand to check for and install an update:
|
|
Close the relevant session when the work is done:
|
|
By default, the background daemon closes its headless browser and exits after a period of inactivity. A session configured for restoration saves state according to its settings. Explicitly running close ends the task sooner and makes the lifetime of login state easier to manage.
Before deleting a local test profile, temporary state file, or screenshot containing sensitive data, make sure it is not the only backup of test credentials or the only test evidence. Handle production-account state according to your organization’s credential-cleanup process.
When to use Playwright or DevTools MCP instead
The agent-browser CLI is useful for quick agent-driven exploration and page checks. For long-lived end-to-end suites, complex fixtures, test reports, network interception, or fine-grained device emulation, a testing framework such as Playwright is easier to maintain. The site’s browser automation comparison explains how the tools differ; the Agent Skills introduction covers installing and loading Skills.
When choosing a tool, write down which page and account to test, which actions are allowed, and when the run should stop. Switching to a CLI does not remove login-state or production-permission risks.
Conclusion
The shortest path to using agent-browser is to install the browser, read an interactive snapshot, act on current references, then wait for and confirm the page result. Before connecting a real test account, add isolated sessions, state-file protection, a domain allowlist, an action policy, and host-level isolation.
Do not treat a --session name, page-output boundary, or domain rule by itself as a complete security sandbox. Verify the script locally or in staging, then grant only the actions it needs.