Commit Graph

50 Commits

Author SHA1 Message Date
ShawnPana 77bbfbbb66 fix INSTALL_DIR scoping in install.sh, use cross-platform cloudflared fix in doctor
- Pass INSTALL_DIR to sh instead of curl so profile-use installs to
  the correct location (~/.browser-use/bin/)
- Replace macOS-specific 'brew install cloudflared' with generic link
2026-03-19 22:08:35 -07:00
ShawnPana 54f3febdfa address PR review comments: fix cloud v2 --help, guard double signal, error to stderr, stale port
- Narrow cloud --help intercept to only fire when --help is immediately
  after 'cloud', so 'cloud v2 --help' still shows OpenAPI endpoints
- Guard signal handler against concurrent shutdown tasks on repeated signals
- Route error response bodies to stderr in cloud REST commands
- Replace stale port 49200 in README Windows troubleshooting
2026-03-19 22:04:34 -07:00
ShawnPana 694a111fad add upload command to CLI, extract find_file_input_near_element to BrowserSession
- Add `browser-use upload <index> <path>` command for uploading files to
  file input elements via the CLI
- Extract find_file_input_near_element from nested closures in tools/service.py
  to a reusable method on BrowserSession, deduplicating two copies
- Add BrowserWrapper.upload() for the Python REPL
- Resolve file paths to absolute on the client side before sending to daemon
- Update SKILL.md files and README with upload command docs
2026-03-19 17:02:34 -07:00
ShawnPana d3e1818496 consolidate CLI files under ~/.browser-use/, add profile-use integration and doctor checks
Unify all CLI-managed files under ~/.browser-use/ (config, sockets, PIDs,
binaries, tunnels) instead of scattering across ~/.config/browser-use/ and
~/.browser-use/run/. Add profile-use Go binary as managed subcommand via
browser-use profile, with auto-download fallback and install.sh integration.
Wire cloudflared and profile-use availability checks into browser-use doctor.
2026-03-18 16:16:28 -07:00
ShawnPana bfa886afea add cloud command and config utilities
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-15 10:12:49 -07:00
ShawnPana 3318f56318 simplify CLI infrastructure: single-session daemon, remove install modes, streamline setup
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-15 10:12:41 -07:00
ShawnPana c93a867a85 add API key signup URL to cloud command error message
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-12 16:01:27 -07:00
ShawnPana 0dc2fc5a6f remove run command and agent infrastructure from CLI
The `run` command pulled in heavy SDK dependencies (openai, anthropic,
google), had a bug (await on sync get_llm), and is superseded by
`browser-use cloud` for agent execution. CLI is now purely a browser
automation interface.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-12 11:44:13 -07:00
ShawnPana 91e987acdc add browser-use cloud command: generic REST passthrough to Cloud API
Login/logout with API key persistence, versioned REST calls (v2/v3),
task polling, and OpenAPI-driven help. Stdlib only, no daemon needed.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-12 11:13:43 -07:00
ShawnPana 4be221386b changes 2026-03-11 12:57:50 -07:00
ShawnPana 859cb97063 simplify daemon architecture: single session, socket-as-liveness, no PID/lock files
Replace the multi-session server (server.py, SessionRegistry, portalocker locking,
PID files, orphan detection) with a minimal daemon (daemon.py) that holds one
BrowserSession in memory. Socket file existence = alive. Auto-exits when browser
dies via CDP watchdog.

-2277 lines, +142 lines across 20 files.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-03 19:05:44 -08:00
ShawnPana 39698e58e4 strip cloud/remote commands from skill_cli
Remove all cloud API paths from the CLI while leaving core library
cloud support (BrowserSession(use_cloud=True), browser/cloud/) untouched.

Deleted: api_key.py, cloud_task.py, cloud_session.py
Removed: --browser remote, cloud-only run flags, task/session subcommands,
cloud profile ops (create/update/delete/sync), remote mode validation
Kept: tunnel (just Cloudflare), all local commands, install_config.py

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-03 15:56:31 -08:00
Laith Weinberger 8ebe4385ed fix: preserve non-ASCII chars in all remaining JSON file outputs 2026-03-01 14:19:38 -05:00
Saurav Panda 3f63677756 new direct cli mode 2026-02-19 10:18:12 -08:00
ShawnPana a1d20ed81c fix(cli): include --remote-only in remote mode error messages
Previously only suggested --full, but --remote-only is a lighter-weight
option when users only need cloud browser support.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-12 10:26:31 -08:00
ShawnPana 4d8c4e5e48 refactor(cli): consolidate tunnel code into single tunnel.py
- Rename tunnel_manager.py to tunnel.py
- Remove dead code: commands/tunnel.py (session-scoped implementation never reached)
- Remove TunnelInfo dataclass and tunnels field from sessions.py
- Remove tunnel routing from server.py (unreachable code path)
- Update imports in main.py, doctor.py, setup.py, and tests

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-12 02:09:55 -08:00
ShawnPana 7706c55532 refactor(cli): consolidate SDK/task/session files into cloud_task.py and cloud_session.py
- Create commands/utils.py with SDK singleton and format_duration helper
- Merge task_management.py into cloud_task.py (SDK wrappers + CLI handlers)
- Create cloud_session.py from session parts of cloud_task.py + session_management.py
- Delete sdk.py, task_management.py, session_management.py
- Update imports in main.py, agent.py, profile.py, __init__.py

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-12 01:47:44 -08:00
ShawnPana 5aeb6beeb5 style: fix ruff lint/format issues
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-12 01:07:22 -08:00
ShawnPana 79e91e6adf fix(cli): update install script URL to /cli/install.sh
Update all references from browser-use.com/install.sh to
browser-use.com/cli/install.sh across documentation and code.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-12 00:24:48 -08:00
ShawnPana 22d7c53700 fix(cli): revert chat.py changes, hardcode browser-use models in CLI
Reverts changes to browser_use/llm/browser_use/chat.py to keep
CLI changes isolated. Browser-use models are now hardcoded in
agent.py instead of importing from chat.py.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-11 23:56:15 -08:00
ShawnPana fae720ba77 fix(cli): address cubic review concerns
- Forward all cloud-only flags in _handle_remote_run_with_wait
  Previously only forwarded 6 params; now includes session_id, vision,
  metadata, secrets, allowed_domains, skill_ids, structured_output,
  judge, judge_ground_truth, plus session creation for profile/proxy

- Use asyncio.to_thread for blocking SDK call in poll_until_complete
  Prevents client.tasks.get_task from blocking the event loop while
  polling for task completion

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-11 23:53:25 -08:00
ShawnPana af9383a2c7 refactor(cli): use SDK verified model lists instead of hardcoded prefixes
- Replace _get_provider_from_model() prefix inference (gpt-*, claude-*, etc.)
  with _get_provider_for_model() that checks SDK Literal types directly:
  - OpenAI: openai.types.shared.chat_model.ChatModel
  - Anthropic: anthropic.types.model_param.ModelParam
  - Google: browser_use.llm.google.chat.VerifiedGeminiModels
  - Browser-Use: VALID_BROWSER_USE_MODELS constant

- Add VALID_BROWSER_USE_MODELS constant to ChatBrowserUse for consistency

- Simplify get_llm() to use native browser-use Chat classes instead of
  langchain imports with try/except fallbacks

- Update default models: o3, claude-sonnet-4-0, gemini-flash-latest

- Remove browser-use/* pattern support (cloud models only)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-11 23:49:11 -08:00
ShawnPana c5dcb52cc9 fix(cli): make poll_until_complete async and show task_id immediately with --wait
Changes:

1. cloud_task.py: Convert poll_until_complete to async
   - Use `await asyncio.sleep()` instead of blocking `time.sleep()`
   - Properly yields control to event loop during polling

2. agent.py: Simplify poll call
   - Just `await cloud_task.poll_until_complete()` directly
   - Remove unnecessary `asyncio.to_thread()` wrapper

3. main.py: Handle --wait directly for immediate feedback
   - Bypass server for remote + run + --wait
   - Print task_id and session_id immediately after task creation
   - Show "waiting... done." progress indicator
   - Handle Ctrl+C gracefully (task continues remotely)
   - Use asyncio.run() for clean event loop management

Before:
  $ browser-use -b remote run "task" --wait
  # (waits silently, then shows everything at once)

After:
  $ browser-use -b remote run "task" --wait
  mode: remote
  task_id: abc123
  session_id: xyz789
  waiting... done.
  status: finished
  output: result here

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-11 23:12:27 -08:00
ShawnPana af1ac137c0 fix(cli): run blocking poll in thread to avoid blocking event loop
Use asyncio.to_thread() for poll_until_complete to prevent time.sleep()
from blocking the async event loop when --wait is used.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-11 19:24:43 -08:00
ShawnPana 1a9f51c541 refactor(cli): use browser-use-sdk for all cloud operations
Replace custom HTTP client with browser-use-sdk for tasks and sessions,
completing the SDK migration started in 8a992229.

## SDK Migration
- Add `sdk.py` with singleton client factory (`get_sdk_client()`)
- Rewrite `cloud_task.py` to use SDK (-300 lines)
- All functions return typed SDK models (TaskView, SessionView, etc.)
- Add `_filter_none()` to omit None values (SDK sends null, API rejects)

## No Client-Side Defaults
- Remove hardcoded defaults from CLI (max_steps, proxy_country, etc.)
- Let API use its own defaults (documented at docs.cloud.browser-use.com)
- Only pass values user explicitly sets

## New CLI Features
- `session create` - create session without task
- `session share <id>` - create/delete public share URLs
- `task list --session <id>` - filter tasks by session
- New task flags: --metadata, --secret, --allowed-domain, --skill-id,
  --structured-output, --judge, --judge-ground-truth, --start-url

## Async by Default
- Change `--no-wait` to `--wait` (flip default behavior)
- Tasks return immediately with task_id by default
- Use `--wait` to block until completion

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-11 19:12:32 -08:00
ShawnPana 8a9922291d refactor(cli): use browser-use-sdk for cloud profile operations
Replace raw urllib HTTP calls with the official browser-use-sdk client
for all cloud profile API operations. This provides:

- Type-safe responses (ProfileView, ProfileListResponse)
- Cleaner error handling via SDK exceptions
- Consistent SDK usage pattern (matches skills/service.py)
- Removes 40 lines of manual HTTP/auth handling from main.py

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-11 16:39:08 -08:00
ShawnPana 7769fbec94 perf(cli): parallelize session stop --all for faster cleanup
Use asyncio.to_thread() with thread pool to stop multiple cloud
sessions concurrently instead of sequentially. Results in ~3.5x
speedup (3.8s vs 13.3s for 5 sessions).

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-10 17:16:27 -08:00
ShawnPana da1380ad77 fix(cli): simplify _run_async to prevent coroutine reuse error
The previous implementation tried to handle various event loop edge
cases but had a bug: if run_until_complete started a coroutine and
then raised RuntimeError, it would try to re-run the same consumed
coroutine with asyncio.run(), causing "cannot reuse already awaited
coroutine" errors.

For CLI code, asyncio.run() is the correct approach as it creates
a fresh event loop. This simplification fixes the confusing error
message when users pass truncated task IDs.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-10 16:31:20 -08:00
ShawnPana 4935afbf44 fix(lint): address ruff linting and formatting issues
- setup.py: Add noqa comment for intentional import check (F401)
- tunnel_manager.py: Add noqa for blocking open in async context (ASYNC230)
- profile.py, setup.py: Auto-format with ruff

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-10 15:45:22 -08:00
ShawnPana 35271ed802 fix: address cubic-dev-ai code review concerns from PR #4078
- agent.py: Move API key check inside remote mode block only, allowing
  local mode to work with OPENAI/ANTHROPIC keys without BROWSER_USE_API_KEY
- tunnel_manager.py: Close log file handle on success path to prevent
  file descriptor leak
- profile.py: Use stderr for progress messages when --json flag is set;
  add cleanup_cloud_profile() to delete orphaned cloud profiles on sync failure
- install.sh: Add guard for --api-key requiring a value; warn on unknown
  arguments instead of silently ignoring; fix read -p with < /dev/tty
  for piped install (curl | bash)
- test_setup_command.py: Remove all unittest.mock usage per repo guidelines,
  replace with real function calls that verify structure and logic

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-10 15:38:01 -08:00
ShawnPana 723f3335b2 feat(cli): add token-efficient task monitoring with duration display
- Default task status shows only latest step (token efficient for agents)
- Add --compact/-c flag to show all steps with reasoning
- Add --verbose/-v flag to show all steps with URLs + actions
- Add --last/-n, --reverse/-r, --step/-s flags for navigating long tasks
- Display duration for tasks (e.g., "18s", "5m 13s") and sessions
- Format proxy cost to 2 decimal places in session output
- Update SKILL.md docs with recommended monitoring workflow
2026-02-10 14:39:20 -08:00
ShawnPana a568f45979 feat(cli): add cloud task/session management and subagent support
Cloud API Integration:
- Add cloud_task.py with full Cloud API client (tasks, sessions)
- Support for task creation, status polling, stopping, and logs
- Session management: create, list, get, stop, delete

Agent Task Options (remote mode):
- --llm: specify model (gpt-4o, claude-sonnet-4-20250514, gemini-2.0-flash)
- --proxy-country: proxy location (default: us)
- --session-id: reuse existing cloud session
- --keep-alive: preserve session after task
- --no-wait: async execution, return task_id immediately
- --stream: stream status updates
- --flash: fast execution mode
- --thinking: extended reasoning
- --vision/--no-vision: control vision capability

CLI Commands:
- task list [--limit N] [--status running|finished] [--json]
- task status <task-id> [--json]
- task stop <task-id>
- task logs <task-id>
- session list [--limit N] [--status active|stopped] [--json]
- session get <session-id> [--json]
- session stop <session-id> | --all

Documentation:
- Add comprehensive subagent examples to SKILL.md files
- Document session=agent, task=work mental model
- Examples for parallel agents, session reuse, agent management
2026-02-10 12:33:05 -08:00
ShawnPana f40235242a refactor: remove pycloudflared, install cloudflared directly in install.sh
- Remove pycloudflared dependency from pyproject.toml
- Simplify tunnel_manager.py to just use shutil.which('cloudflared')
- Add install_cloudflared() to install.sh that downloads binary from
  official Cloudflare GitHub releases based on platform/arch
- Update SKILL.md with manual cloudflared install instructions
- Update setup.py messages for missing cloudflared

install.sh supported platforms:
- Linux (x86_64, arm64) - full support, downloads binary to ~/.local/bin
- macOS (Intel, Apple Silicon) - full support, uses brew or direct download
- Windows WSL - works (treated as Linux)
- Native Windows - not supported (bash script), use manual install
2026-02-09 17:03:56 -08:00
ShawnPana 9520a0b04e feat: frictionless installation system with setup/doctor commands
- Add TunnelManager for auto-install cloudflared via pycloudflared
- Add 'browser-use setup' command with profile-based configuration
- Add 'browser-use doctor' command for health checks
- Add install.sh bootstrap script (dev testing version)
- Add pycloudflared dependency
- Add comprehensive tests for new functionality
2026-02-09 16:09:38 -08:00
Gregor Žunič 9d7a0c74ed Add bu tunnel command and remote-browser skill
- New `tunnel` command: expose localhost ports via Cloudflare quick tunnels
  (`bu tunnel 3000` → trycloudflare.com URL, idempotent, auto-cleanup on session close)
- New `skills/remote-browser/SKILL.md`: guides sandboxed agents through
  cloud browser + tunnel workflow
- TunnelInfo dataclass on SessionInfo for tunnel lifecycle management
- Tunnel dispatch in both SessionServer and CLI arg parser

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-09 10:14:42 -08:00
ShawnPana 92de59c6cc fix(cli): fix pyright type errors in CLI
- Remove invalid cdp_url parameter from create_browser_session calls
- Replace deleted GetCookiesEvent with direct _cdp_get_cookies() call
- Add type assertion for cookies_file after error check
- Use unique variable names for CDP results to avoid type conflicts
- Add type ignores for CDP typed return values used as dicts
2026-02-02 13:05:11 -08:00
ShawnPana ad47a97518 style: apply ruff formatting 2026-02-02 10:51:08 -08:00
ShawnPana a961021670 refactor(cli): move CDP logic into CLI, remove events and watchdogs
Move all CLI-specific CDP logic directly into browser.py command
handlers instead of using events and watchdogs. This keeps the CLI
self-contained and avoids adding CLI-specific code to the core library.

- Remove 14 CLI-specific events from events.py
- Remove 3 watchdog files (cookies, interactions, wait)
- Remove watchdog registrations from session.py
- Implement direct CDP calls in browser.py for cookies, wait, hover,
  dblclick, rightclick, and get commands
2026-02-02 10:44:30 -08:00
ShawnPana 2d992c3726 feat(cli): add cloud profile management and cookie sync
- Add cloud profile commands: list, create, get, update, delete
- Add profile sync command to sync local Chrome cookies to cloud
- Add profile cookies command to list cookies by domain
- Add cookies export/import commands for bulk transfer
- Optimize cookie import using Network.setCookies (bulk API)
- Real browser now runs headless by default (use --headed for visible)
- Support --domain flag for syncing specific domain cookies only
- Update SKILL.md with cloud profile workflow documentation
2026-01-31 20:02:50 -08:00
ShawnPana 9abfc327cc feat(cli): add get command for info retrieval (title, html, text, value, attributes, bbox)
Adds information retrieval commands to the browser-use CLI:
- get title: page title
- get html: full page or element HTML via selector
- get text: text content of element by index
- get value: input/textarea value by index
- get attributes: all attributes of element by index
- get bbox: bounding box (x, y, width, height) of element
2026-01-31 17:34:33 -08:00
ShawnPana 3ca625b75e feat(cli): add hover, dblclick, rightclick interaction commands
Adds mouse interaction commands to the browser-use CLI:
- hover: move mouse over element (triggers CSS :hover effects)
- dblclick: double-click element
- rightclick: right-click element (context menu)
2026-01-31 17:28:20 -08:00
ShawnPana 33e03b7b0f feat(cli): add wait command for selector and text conditions
Adds wait conditions to the browser-use CLI with two subcommands:
- wait selector: wait for CSS selector with state options (visible, hidden, attached, detached)
- wait text: wait for text to appear on the page
Both support custom timeout in milliseconds.
2026-01-31 17:17:35 -08:00
ShawnPana 45d244e01c feat(cli): add cookies command for get/set/clear operations
Adds cookie management to the browser-use CLI with three subcommands:
- cookies get: retrieve all cookies or filter by URL
- cookies set: create cookies with domain, path, secure, httpOnly options
- cookies clear: remove all cookies or filter by URL
2026-01-31 17:09:35 -08:00
BouquetAntoine 1a01e5dff7 feat(cli): add ChatBrowserUse support for BROWSER_USE_API_KEY
The CLI 'run' command now supports BROWSER_USE_API_KEY as an LLM option,
using ChatBrowserUse which is optimized for browser automation tasks.

This aligns the CLI behavior with the documented supported models at
https://docs.browser-use.com/supported-models which shows ChatBrowserUse
as a valid LLM option using BROWSER_USE_API_KEY.

Changes:
- Add ChatBrowserUse as first LLM option in get_llm() when BROWSER_USE_API_KEY is set
- Update error message to mention BROWSER_USE_API_KEY
2026-01-22 17:18:08 +01:00
Gregor Žunič b6bdc17bcb addresses cubic 2026-01-21 22:17:07 -08:00
Gregor Žunič 5fc3a428c7 better remote session management 2026-01-21 22:12:51 -08:00
Gregor Žunič c7c5cae20e remote browser fixes + readme 2026-01-21 21:49:26 -08:00
Gregor Žunič 5e75df3eb0 fix: Clean up Python command output format 2026-01-21 21:16:20 -08:00
Gregor Žunič 4716ae50ce fix: State command now outputs LLM representation, add CLI aliases
- State command outputs same format that browser-use agents see
- Added aliases: bu, browser (all work the same)
- Headed mode now correctly shows browser window
2026-01-19 09:36:20 -08:00
Gregor Žunič c4ffaca6e7 feat: Add fast CLI for browser automation (bu command)
Implements a fast, persistent browser automation CLI per CLI_SPEC.md:

- Fast CLI layer using stdlib only (<50ms startup)
- Session server with Unix socket IPC (TCP on Windows)
- Browser modes: chromium, real, remote
- Commands: open, click, type, input, scroll, back, screenshot,
  state, switch, close-tab, keys, select, eval, extract
- Python execution with persistent namespace (Jupyter-like REPL)
- Agent task execution (requires API key)
- JSON output mode

The CLI maintains browser sessions across commands, enabling complex
multi-step workflows. Includes Claude skill description for AI-assisted
browser automation.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-19 01:05:35 -08:00