Commit Graph

709 Commits

Author SHA1 Message Date
Saurav Panda 0d59615688 security: wrap _safe_import to close __import__.__globals__ bypass
Previously __import__ was a plain closure whose __globals__ contained
this module's real __builtins__, so sandboxed code could escape via
__import__.__globals__['__builtins__']['__import__']('os').

Wrap _safe_import in _SafeBuiltin (same hardening as other builtins) so
its __globals__ attribute is not reachable from user code. Also resolve
_real_import at wrap-time rather than closing over __builtins__ to keep
the closure minimal.
2026-04-14 17:55:43 -07:00
Saurav Panda b53dc30564 security: harden PythonSession sandbox against __globals__ and module leak bypasses
Replace closure wrapper with a callable class (_SafeBuiltin) built in an
isolated exec namespace. Closures leak this module's globals via
wrapper.__globals__ (print.__globals__['io'], print.__globals__['Path']).
The callable class has no __globals__ attribute at instance level, and
the class methods' __globals__ is the isolated namespace instead of this
module.

Also block pathlib and asyncio imports — both modules import os directly,
so Path.cwd.__globals__['os'] and asyncio.subprocess were escape routes.
2026-04-14 17:52:15 -07:00
Saurav Panda 6118f5218d security: sandbox PythonSession namespace, block dangerous modules and builtins
Remove os from the default namespace and restrict __builtins__ to a
curated safe set (no open/exec/eval/compile). Add an import guard that
blocks os, subprocess, shutil, sys, builtins, and other system-access
modules. Preserve __build_class__ so class definitions still work.

Wrap builtin functions to prevent __self__ leaking the builtins module.
Remove Path and asyncio from pre-loaded namespace to close
Path.cwd.__globals__ and asyncio.sys.modules escape routes.
2026-04-14 16:00:05 -07:00
Saurav Panda 35eef03ecd security: sandbox PythonSession namespace, block dangerous modules and builtins 2026-04-14 11:49:48 -07:00
Alezander9 f8f7be2e90 Fix test assertions to match updated error messages 2026-04-08 22:12:16 -07:00
ShawnPana 454dbfdaba style: flatten assert to pass pre-commit formatter 2026-04-02 12:34:27 -07:00
ShawnPana 7db93b7ac7 fix: accept shutting-down race in test_close_orphaned_daemon
SIGTERM may not kill daemon before the CLI re-probes, producing a
"daemon may still be shutting down" warning instead of "Browser closed".
2026-04-02 12:28:15 -07:00
ShawnPana f8fdddc66d fix: update cloud tests to use config.json for API key instead of env var 2026-04-02 11:56:54 -07:00
ShawnPana 1aa6f6dd3b fix: remove tests for deleted TunnelManager.is_available() 2026-04-01 22:06:02 -07:00
ShawnPana addefa0352 fix: add ActionHandler to test SessionInfo constructions
test_cli_upload and test_cli_coordinate_click create SessionInfo
without actions, hitting the type-narrowing guard. Now provide
ActionHandler in all test cases.
2026-04-01 21:58:58 -07:00
ShawnPana c312191e8e fix: update test_cli_connect for --connect deprecation 2026-04-01 20:06:42 -07:00
ShawnPana 0bf1f02d97 fix: CI failures — ruff formatting, type errors, test_setup_command
- Ruff format all skill_cli and test files
- Fix type: get_config_value returns str|int|None, callers cast properly
- Fix type: BrowserWrapper.actions is non-optional (always provided)
- Fix type: config comparison uses 'is' not '=='
- Rewrite test_setup_command for new setup.handle(yes=True) API
- Add None guard in test_cli_lifecycle for state file
2026-04-01 19:58:33 -07:00
ShawnPana 254f117cf2 chore: remove mock-based robustness tests (violates no-mock policy)
test_cli_lifecycle.py already covers the important paths with real
daemon subprocesses. The mock-heavy tests duplicated coverage with
less confidence.
2026-04-01 19:36:16 -07:00
ShawnPana 8577c789eb fix: close log file handle on successful daemon start in test 2026-04-01 19:29:27 -07:00
ShawnPana ca05f46352 refactor: remove --agent/register/tab-ownership, sessions-as-agents model
Multi-agent isolation is now achieved through separate sessions
(--session NAME), each with its own browser. Removed:
- register command and agents.json
- --agent flag and agent_id plumbing
- TabOwnershipManager and all tab locking logic
- dispatch lock and focus swapping between agents
- tab_ownership.py (deleted)
- test_tab_ownership.py (deleted)

Simplified tab commands: no lock checks, no _tab_list injection,
no _resolved_target_id params. agent_focus_target_id stays for
single-agent tab tracking.

Tested: 3 concurrent subagents on separate cloud sessions,
3 concurrent subagents on separate headless Chromium sessions.
2026-04-01 17:34:46 -07:00
ShawnPana d59c0e6984 fix: CLI reconciliation gaps found by codex review
- ensure_daemon now phase-aware: waits for initializing/starting/
  shutting_down with staleness timeouts, errors on unhealthy sessions
- _close_session only cleans files after confirmed PID death
- _handle_sessions won't delete live daemon's files on stale terminal state
- _probe_session uses socket_pid for split-brain PID resolution
- _is_daemon_process works on Windows (wmic)
- Updated + added robustness tests (codex-authored)
2026-03-30 19:49:57 -07:00
ShawnPana 7c7fd37220 test: add daemon lifecycle tests with real subprocess daemons
15 tests covering state file transitions, _probe_session branches (live
daemon, dead PID, no files, corrupt state), close via socket, close
orphaned daemon, close --all with mixed sessions, sessions listing with
phase column, and stale/terminal state cleanup.

Uses real daemon subprocesses with BROWSER_USE_HOME overridden to temp
dirs. No mocking.
2026-03-30 19:09:00 -07:00
ShawnPana 1f8b4a5346 fix: rewrite register tests to use real code path via subprocess 2026-03-27 11:49:47 -07:00
ShawnPana 6bb73ab274 merge upstream/main, resolve install_lite.sh conflict (take upstream) 2026-03-26 11:40:33 -07:00
ShawnPana 2f41a42eab extract CLI deps to requirements-cli.txt + add CI test 2026-03-26 09:27:18 -07:00
ShawnPana 31694df283 feat: multi-agent tab isolation for --connect mode
Multiple agents can share one browser via --connect without interfering
with each other. Each agent registers with `browser-use register` to get
a numeric index, then passes it with `--connect <index>` on every command.

- Tab locking: mutating commands (click, type, open) lock the tab to the
  agent. Other agents get an error if they try to mutate the same tab.
  Read-only commands (state, screenshot) work on any tab.
- Agent registry: agents.json tracks registered agents with timestamps.
  Expired agents (5min inactive) get cleaned up automatically.
- Session lock: prevents double BrowserSession creation when two agents
  connect simultaneously.
- Focus swap: daemon swaps agent_focus_target_id and cached_selector_map
  per-agent before each command, so element indices are isolated.
2026-03-24 16:38:53 -07:00
Laith Weinberger 544ad89287 widen retry timing assertions so CI stops flaking 2026-03-21 02:20:17 -04:00
shawn pana a2c2fa33aa Merge branch 'main' into cli 2026-03-20 09:34:45 -07:00
reformedot ad41865559 Refactor User-Agent assertion in CDP headers test
- Updated the assertion for the User-Agent header in the /json/version endpoint test to improve readability by using a multi-line format.
- This change enhances the clarity of the test's intent while maintaining the existing validation logic.

These modifications contribute to better maintainability of the test code.
2026-03-20 00:47:59 -07:00
reformedot f64f587d09 Enhance header validation in CDP client tests
- Improved assertions in tests to ensure all user-provided headers are present in the additional_headers.
- Added checks to confirm that the User-Agent header is injected for remote connections, ensuring consistent behavior across tests.
- Updated the test for the /json/version endpoint to validate the presence and format of the User-Agent header.

These changes enhance the reliability of header handling in the CDP client tests.
2026-03-20 00:43:15 -07:00
ShawnPana c26f228e5a fix cloud --help to show custom usage, tighten test assertions
- Intercept `cloud --help` early so it routes to _print_cloud_usage()
  instead of argparse's generic stub
- Remove permissive `or 'cloud'` fallback in epilog test assertion
- Delete no-op regex test that didn't verify actual code
- Tighten default socket path assertion to check 'default.sock'
2026-03-19 21:48:28 -07:00
ShawnPana f0ca934ae0 fix pyright errors in test_cli_cloud.py: type handler callbacks correctly 2026-03-19 21:12:32 -07:00
ShawnPana 91c02012c3 merge origin/main into cli, resolve agent.py delete conflict 2026-03-19 21:06:38 -07:00
Saurav Panda 6d86be3a6b fix: detect skeleton screens and retry navigation for blank SPA pages 2026-03-19 18:48:47 -07:00
Saurav Panda 0ee771d0fa updated to use temp_path by pytest 2026-03-19 18:19:36 -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
Saurav Panda cc1cf2b1c7 Merge branch 'main' into fix-image-url-stripping 2026-03-19 15:34:27 -07:00
Saurav Panda 9445a9ff9e fix image URLs stripped from extracted markdown 2026-03-19 15:29:06 -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 bff2918558 add --connect flag for Chrome auto-discovery and fix daemon shutdown for external browsers
Adds `--connect` to auto-discover running Chrome instances via DevToolsActivePort
files and well-known port probing, eliminating manual CDP URL construction. Fixes
daemon process hanging on `close` when connected to external browsers (--connect,
--cdp-url, cloud) by calling stop() (disconnect) instead of kill() (terminate).
2026-03-18 09:41:58 -07:00
Ahmed Aly 0d0eae16d2 zach/chore: fix ruff 2026-03-17 03:48:54 +00:00
Ahmed Aly e8d1681cd5 zach/chore: strip password field values from DOM snapshots sent to LLM 2026-03-17 03:26:24 +00: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 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
Saurav Panda 2552caeca4 fixed code styling issue 2026-02-25 12:26:10 -08:00
Saurav Panda 8270346ccf improved csv file generation 2026-02-25 11:45:05 -08:00
Saurav Panda 95215d6211 Add save_as_pdf agent action for CDP-based page-to-PDF export 2026-02-24 18:35:34 -08:00
Saurav Panda de8039288d Merge branch 'main' into browser-use-radio-button-interaction-issue 2026-02-23 16:55:36 -08:00
Saurav Panda 84babc6b75 fix radio button click occlusion when label overlaps input 2026-02-23 16:19:05 -08:00
Saurav Panda e50588f3c7 fixed styling issues 2026-02-23 15:24:40 -08:00
Saurav Panda 6713afc636 updated _navigate_and_wait 2026-02-21 19:45:54 -08:00
Saurav Panda 69d96c1f45 Merge branch 'main' into cli-add-cordinate-clicking 2026-02-19 18:45:52 -08:00