Command Line Interface
Relevant source files
The following files were used as context for generating this wiki page:
The Command Line Interface (CLI) in the browser-use project serves as the primary entry point for terminal-based interaction with AI browser agents. It allows developers and users to trigger automation tasks, configure browser environments, and manage agent execution directly from a terminal emulator without the need for a graphical user interface (GUI).
The CLI architecture is designed to parse user-provided arguments, initialize the core Agent and Browser components, and pipe terminal inputs into the automation pipeline. This facilitates headless execution, integration into CI/CD pipelines, and rapid testing of browser automation scripts.
Sources: examples/ui/README.md:1-11, README.md:46-64
Execution and Entry Points
The project provides specific scripts for terminal interaction. The primary script dedicated to this functionality is command_line.py, which is categorized under the "User Interfaces" of the project as the Terminal interface.
Basic Execution Flow
To run the browser automation via the command line, users typically utilize the Python interpreter to execute the UI scripts. The standard installation involves setting up the environment via pip and installing the necessary browser drivers via Playwright.
The flow begins with the user providing a task description via the terminal, which is then passed to the Agent class for execution.
Sources: examples/ui/README.md:9, README.md:46-52, examples/ui/gradio_demo.py:53-70
Configuration and Argument Parsing
The CLI relies on a combination of environment variables (loaded via python-dotenv) and script arguments to configure the browser and LLM behavior. Key configuration parameters are derived from the BrowserContextConfig and BrowserConfig classes.
Environment Setup
CLI scripts typically require an .env file containing API keys for the chosen LLM provider (e.g., OPENAI_API_KEY).
Sources: README.md:65-68, examples/ui/gradio_demo.py:19
Configurable Parameters
The following table outlines common configurations often exposed through terminal arguments or environment variables:
| Parameter | Type | Default | Description |
|---|---|---|---|
headless | bool | True | Whether to run the browser without a visible window. |
wait_between_actions | float | 1.0 | Delay in seconds between sequential agent actions. |
browser_window_size | dict | 1280x1100 | The resolution of the browser viewport. |
highlight_elements | bool | True | Visual markers for elements the agent is interacting with. |
save_recording_path | str | None | Directory to save video files of the browser session. |
Sources: browser_use/browser/context.py:54-120, examples/ui/gradio_demo.py:80-90
Internal Logic and Data Flow
When a task is initiated via the CLI, the system orchestrates communication between the MessageManager, the Controller, and the BrowserContext.
The CLI acts as the initial invoker, while the Agent manages the state loop. The Controller translates abstract actions (like click_element or go_to_url) into concrete Playwright commands.
Sources: browser_use/controller/service.py:382-440, browser_use/browser/context.py:440-460, browser_use/agent/message_manager/service.py:115-130
Command Implementation Details
The CLI scripts leverage the browser-use library's ability to handle complex navigation and interaction. Scripts like command_line.py are expected to wrap the Agent.run() method, which is an asynchronous operation.
Dependency Context
The CLI functionality depends on several core packages listed in the project configuration:
langchain: Orchestrates LLM calls.playwright: Powers the actual browser manipulation.pydantic: Validates the data structures for actions and states.
Sources: pyproject.toml:13-35
Summary
The Command Line Interface provides a high-efficiency path for executing browser-use agents. By parsing terminal inputs and mapping them to BrowserContextConfig and Agent parameters, it enables flexible automation that can range from simple web searches to complex multi-step workflows like job applications or shopping tasks. It serves as the foundational interface for developers to build further integrations, such as Slack or Discord bots.
Sources: examples/ui/README.md:1-11, README.md:160-180