Skip to content

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

fix click return values

Nick Sweeting058b20d7e713
diff --git a/browser_use/browser/default_action_watchdog.py b/browser_use/browser/default_action_watchdog.py
index 27450380e..b59c1d18d 100644
--- a/browser_use/browser/default_action_watchdog.py
+++ b/browser_use/browser/default_action_watchdog.py
@@ -35,7 +35,7 @@ UploadFileEvent.model_rebuild()
class DefaultActionWatchdog(BaseWatchdog):
"""Handles default browser actions like click, type, and scroll using CDP."""
- async def on_ClickElementEvent(self, event: ClickElementEvent) -> dict[str, bool | str] | None:
+ async def on_ClickElementEvent(self, event: ClickElementEvent) -> dict[str, str] | None:
"""Handle click request with CDP."""
try:
# Use the provided node
@@ -56,7 +56,7 @@ class DefaultActionWatchdog(BaseWatchdog):
details={'index': index_for_logging},
)
)
- return {'success': False, 'error': 'Click triggered a FileInputElement which could not be handled, use the dedicated upload file function instead'}
+ raise Exception('Click triggered a FileInputElement which could not be handled, use the dedicated upload file function instead')
# Perform the actual click using internal implementation
download_path = await self._click_element_node_impl(
@@ -86,8 +86,7 @@ class DefaultActionWatchdog(BaseWatchdog):
# Return download_path if any
if download_path:
- return {'success': True, 'download_path': download_path}
- return {'success': True}
+ return {'download_path': download_path}
except Exception as e:
self.event_bus.dispatch(
BrowserErrorEvent(
@@ -96,6 +95,7 @@ class DefaultActionWatchdog(BaseWatchdog):
details={'index': index_for_logging if 'index_for_logging' in locals() else 'unknown'},
)
)
+ raise
async def on_TypeTextEvent(self, event: TypeTextEvent) -> dict[str, bool] | None:
"""Handle text input request with CDP."""
diff --git a/browser_use/controller/service.py b/browser_use/controller/service.py
index d1488ddc2..ea84cc563 100644
--- a/browser_use/controller/service.py
+++ b/browser_use/controller/service.py
@@ -181,7 +181,7 @@ class Controller(Generic[Context]):
raise ValueError(f'Failed to click element {params.index}: {e}') from e
# Get the result if any (e.g., download path)
- result = await event.event_result()
+ result = await event.event_result(raise_if_none=False, raise_if_any=True)
if result:
download_path = result.get('download_path')
if download_path:
diff --git a/browser_use/controller/views.py b/browser_use/controller/views.py
index 06edc7e53..72fdd4f72 100644
--- a/browser_use/controller/views.py
+++ b/browser_use/controller/views.py
@@ -13,7 +13,7 @@ class GoToUrlAction(BaseModel):
new_tab: bool = False # True to open in new tab, False to navigate in current tab
-class ClickElementAction(BaseModel):
+class ClickElementAction(BaseModel[dict[str, str] | None]):
index: int
new_tab: bool = Field(default=False, description='set True to open any resulting navigation in a new tab, False otherwise')
expect_download: bool = Field(default=False, description='set True if expecting a download, False otherwise')
diff --git a/browser_use/dom/views.py b/browser_use/dom/views.py
index dac31d0c9..0e0e724eb 100644
--- a/browser_use/dom/views.py
+++ b/browser_use/dom/views.py
@@ -155,6 +155,22 @@ class EnhancedSnapshotNode:
"""Stacking contexts from the layout tree"""
+# @dataclass(slots=True)
+# class SuperSelector:
+# node_id: int
+# backend_node_id: int
+# frame_id: str | None
+# target_id: str
+
+# node_type: NodeType
+# node_name: str
+
+# # is_visible: bool | None
+# # is_scrollable: bool | None
+
+# element_index: int | None
+
+
@dataclass(slots=True)
class EnhancedDOMTreeNode:
"""