Skip to content

Open-source Python library for AI browser agents, plus Browser Use Cloud: stealth browsers and a hosted agent API.

Merge remote-tracking branch 'origin/main' into codex/browser-use-rust-wheel

Gregor Žunič9a864e81cf33
diff --cc browser_use/beta/service.py
index e6865091a,1d206a7f5..298a949a3
--- a/browser_use/beta/service.py
+++ b/browser_use/beta/service.py
@@@ -12,7 -12,7 +12,8 @@@ import mimetype
import os
import re
import shutil
+ import subprocess
+import sys
import tempfile
import time
from collections.abc import Awaitable, Callable
@@@ -198,29 -193,33 +197,44 @@@ def find_browser_use_terminal_binary()
but_install_dir / 'browser-use-terminal',
]
for candidate in candidates:
- if candidate.exists():
+ if candidate.exists() and _terminal_supports_sdk_server(candidate):
return str(candidate)
path_binary = shutil.which('browser-use-terminal')
- if path_binary:
+ if path_binary and _terminal_supports_sdk_server(Path(path_binary)):
return path_binary
- raise RustAgentError(
+ raise BetaAgentError(
f'Could not find browser-use-terminal. Install Browser Use Terminal with `{TERMINAL_INSTALL_COMMAND}`, '
- 'or set BROWSER_USE_TERMINAL_BINARY to a built terminal CLI.'
+ 'install browser-use-core, or set BROWSER_USE_TERMINAL_BINARY to a built terminal CLI.'
)
+def _find_packaged_browser_use_terminal_binary() -> str | None:
+ try:
+ from browser_use_core import binary_path
+ except Exception:
+ return None
+ try:
+ return binary_path('browser-use-terminal')
+ except Exception:
+ return None
+
+
+ def _terminal_supports_sdk_server(binary: Path) -> bool:
+ """Return whether a terminal binary supports the SDK server subcommand required by this wrapper."""
+ try:
+ result = subprocess.run(
+ [str(binary), '--help'],
+ capture_output=True,
+ text=True,
+ timeout=5,
+ check=False,
+ )
+ except (OSError, subprocess.SubprocessError):
+ return False
+ return 'sdk-server' in f'{result.stdout}\n{result.stderr}'
+
+
-class RustSdkJsonRpcError(RustAgentError):
+class RustSdkJsonRpcError(BetaAgentError):
"""Raised when the Rust SDK server returns a JSON-RPC error."""
def __init__(self, code: int, message: str) -> None:
diff --cc tests/ci/test_beta_agent.py
index d6a742335,794243992..ac762a195
--- a/tests/ci/test_beta_agent.py
+++ b/tests/ci/test_beta_agent.py
@@@ -2683,10 -2635,10 +2683,11 @@@ def test_rust_terminal_binary_finds_def
binary = tmp_path / '.browser-use-terminal' / 'packages' / 'standalone' / 'current' / 'bin' / 'browser-use-terminal'
binary.parent.mkdir(parents=True)
- binary.write_text('#!/bin/sh\n')
+ binary.write_text('#!/bin/sh\nif [ "$1" = "--help" ]; then\n echo "sdk-server"\nfi\n')
+ binary.chmod(0o755)
monkeypatch.delenv('BROWSER_USE_TERMINAL_BINARY', raising=False)
+ monkeypatch.setitem(sys.modules, 'browser_use_core', None)
monkeypatch.chdir(tmp_path)
monkeypatch.setenv('BUT_HOME', str(tmp_path / '.browser-use-terminal'))
monkeypatch.setenv('BUT_INSTALL_DIR', str(tmp_path / '.local' / 'bin'))