官方文档: https://github.com/vercel-labs/agent-browser/blob/main/README.md
This example demonstrates how to use a custom browser executable instead of the bundled Chromium.
# Use custom browser executable
agent-browser --executable-path /path/to/chromium open example.com
agent-browser --executable-path /path/to/chromium snapshot
# Set custom executable path
export AGENT_BROWSER_EXECUTABLE_PATH=/path/to/chromium
# All commands use the custom executable
agent-browser open example.com
agent-browser snapshot
import chromium from '@sparticuz/chromium';
import { BrowserManager } from 'agent-browser';
export async function handler() {
const browser = new BrowserManager();
await browser.launch({
executablePath: await chromium.executablePath(),
headless: true,
});
// ... use browser
}
# macOS
agent-browser --executable-path "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" open example.com
# Linux
agent-browser --executable-path /usr/bin/google-chrome open example.com
# Windows
agent-browser --executable-path "C:\Program Files\Google\Chrome\Application\chrome.exe" open example.com
# Use lightweight Chromium build for serverless
export AGENT_BROWSER_EXECUTABLE_PATH=/path/to/lightweight-chromium
agent-browser open example.com
--executable-path flag or AGENT_BROWSER_EXECUTABLE_PATH environment variable