Skip to content

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

chore: remove dead code found by codex review

ShawnPana01995138f119
diff --git a/browser_use/skill_cli/commands/doctor.py b/browser_use/skill_cli/commands/doctor.py
index 42021b3db..bf6a190c9 100644
--- a/browser_use/skill_cli/commands/doctor.py
+++ b/browser_use/skill_cli/commands/doctor.py
@@ -9,8 +9,6 @@ from typing import Any
logger = logging.getLogger(__name__)
-COMMANDS = {'doctor'}
-
async def handle() -> dict[str, Any]:
"""Run health checks and return results."""
@@ -64,8 +62,7 @@ def _check_browser() -> dict[str, Any]:
try:
from browser_use.browser.profile import BrowserProfile
- # Just check if we can import and create a profile
- profile = BrowserProfile(headless=True)
+ BrowserProfile(headless=True) # verify import + constructor work
return {
'status': 'ok',
'message': 'Browser profile available',
diff --git a/browser_use/skill_cli/commands/utils.py b/browser_use/skill_cli/commands/utils.py
deleted file mode 100644
index 19048e5cc..000000000
--- a/browser_use/skill_cli/commands/utils.py
+++ /dev/null
@@ -1,31 +0,0 @@
-"""Shared utilities for CLI command handlers."""
-
-from datetime import datetime, timezone
-
-
-def format_duration(started_at: datetime | None, finished_at: datetime | None) -> str:
- """Format duration between two timestamps, or elapsed time if still running."""
- if not started_at:
- return ''
-
- try:
- if finished_at:
- end = finished_at
- else:
- end = datetime.now(timezone.utc)
-
- delta = end - started_at
- total_seconds = int(delta.total_seconds())
-
- if total_seconds < 60:
- return f'{total_seconds}s'
- elif total_seconds < 3600:
- minutes = total_seconds // 60
- seconds = total_seconds % 60
- return f'{minutes}m {seconds}s'
- else:
- hours = total_seconds // 3600
- minutes = (total_seconds % 3600) // 60
- return f'{hours}h {minutes}m'
- except Exception:
- return ''
diff --git a/browser_use/skill_cli/python_session.py b/browser_use/skill_cli/python_session.py
index cdcb23b3a..4134d54c9 100644
--- a/browser_use/skill_cli/python_session.py
+++ b/browser_use/skill_cli/python_session.py
@@ -154,12 +154,7 @@ class BrowserWrapper:
self._run(self._goto_async(url))
async def _goto_async(self, url: str) -> None:
- if self._actions:
- await self._actions.navigate(url)
- else:
- from browser_use.browser.events import NavigateToUrlEvent
-
- await self._session.event_bus.dispatch(NavigateToUrlEvent(url=url))
+ await self._actions.navigate(url)
def click(self, index: int) -> None:
"""Click element by index."""
@@ -169,12 +164,7 @@ class BrowserWrapper:
node = await self._session.get_element_by_index(index)
if node is None:
raise ValueError(f'Element index {index} not found')
- if self._actions:
- await self._actions.click_element(node)
- else:
- from browser_use.browser.events import ClickElementEvent
-
- await self._session.event_bus.dispatch(ClickElementEvent(node=node))
+ await self._actions.click_element(node)
def type(self, text: str) -> None:
"""Type text into focused element."""
@@ -197,14 +187,8 @@ class BrowserWrapper:
node = await self._session.get_element_by_index(index)
if node is None:
raise ValueError(f'Element index {index} not found')
- if self._actions:
- await self._actions.click_element(node)
- await self._actions.type_text(node, text)
- else:
- from browser_use.browser.events import ClickElementEvent, TypeTextEvent
-
- await self._session.event_bus.dispatch(ClickElementEvent(node=node))
- await self._session.event_bus.dispatch(TypeTextEvent(node=node, text=text))
+ await self._actions.click_element(node)
+ await self._actions.type_text(node, text)
def upload(self, index: int, path: str) -> None:
"""Upload a file to a file input element."""
@@ -230,24 +214,14 @@ class BrowserWrapper:
if file_input_node is None:
raise ValueError(f'Element {index} is not a file input and no file input found nearby')
- if self._actions:
- await self._actions.upload_file(file_input_node, file_path)
- else:
- from browser_use.browser.events import UploadFileEvent
-
- await self._session.event_bus.dispatch(UploadFileEvent(node=file_input_node, file_path=file_path))
+ await self._actions.upload_file(file_input_node, file_path)
def scroll(self, direction: Literal['up', 'down', 'left', 'right'] = 'down', amount: int = 500) -> None:
"""Scroll the page."""
self._run(self._scroll_async(direction, amount))
async def _scroll_async(self, direction: Literal['up', 'down', 'left', 'right'], amount: int) -> None:
- if self._actions:
- await self._actions.scroll(direction, amount)
- else:
- from browser_use.browser.events import ScrollEvent
-
- await self._session.event_bus.dispatch(ScrollEvent(direction=direction, amount=amount))
+ await self._actions.scroll(direction, amount)
def screenshot(self, path: str | None = None) -> bytes:
"""Take screenshot, optionally save to file."""
@@ -284,24 +258,14 @@ class BrowserWrapper:
self._run(self._keys_async(keys))
async def _keys_async(self, keys: str) -> None:
- if self._actions:
- await self._actions.send_keys(keys)
- else:
- from browser_use.browser.events import SendKeysEvent
-
- await self._session.event_bus.dispatch(SendKeysEvent(keys=keys))
+ await self._actions.send_keys(keys)
def back(self) -> None:
"""Go back in history."""
self._run(self._back_async())
async def _back_async(self) -> None:
- if self._actions:
- await self._actions.go_back()
- else:
- from browser_use.browser.events import GoBackEvent
-
- await self._session.event_bus.dispatch(GoBackEvent())
+ await self._actions.go_back()
def wait(self, seconds: float) -> None:
"""Wait for specified seconds."""
diff --git a/browser_use/skill_cli/utils.py b/browser_use/skill_cli/utils.py
index 4fd724bf1..d91d16ebd 100644
--- a/browser_use/skill_cli/utils.py
+++ b/browser_use/skill_cli/utils.py
@@ -117,52 +117,6 @@ def is_daemon_alive(session: str = 'default') -> bool:
s.close()
-def list_sessions() -> list[dict]:
- """List active daemon sessions by scanning PID files.
-
- Returns list of {'name': str, 'pid': int, 'socket': str} for alive sessions.
- Cleans up stale PID/socket files for dead sessions.
- """
- home_dir = get_home_dir()
- sessions: list[dict] = []
-
- for pid_file in sorted(home_dir.glob('*.pid')):
- session_name = pid_file.stem
- if not session_name:
- continue
-
- try:
- pid = int(pid_file.read_text().strip())
- except (OSError, ValueError):
- # Corrupt PID file — clean up
- pid_file.unlink(missing_ok=True)
- continue
-
- # Check if process is alive
- if not is_process_alive(pid):
- # Dead process — clean up stale files
- pid_file.unlink(missing_ok=True)
- sock_path = get_socket_path(session_name)
- if not sock_path.startswith('tcp://'):
- Path(sock_path).unlink(missing_ok=True)
- continue
-
- sessions.append(
- {
- 'name': session_name,
- 'pid': pid,
- 'socket': get_socket_path(session_name),
- }
- )
-
- return sessions
-
-
-def get_log_path() -> Path:
- """Get log file path for the daemon."""
- return get_home_dir() / 'cli.log'
-
-
def find_chrome_executable() -> str | None:
"""Find Chrome/Chromium executable on the system."""
system = platform.system()