Skip to content

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

click is working again

Nick Sweetinga8817ff65f8b
diff --git a/browser_use/browser/default_action_watchdog.py b/browser_use/browser/default_action_watchdog.py
index b59c1d18d..432077ade 100644
--- a/browser_use/browser/default_action_watchdog.py
+++ b/browser_use/browser/default_action_watchdog.py
@@ -56,7 +56,9 @@ class DefaultActionWatchdog(BaseWatchdog):
details={'index': index_for_logging},
)
)
- raise Exception('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(
@@ -228,7 +230,8 @@ class DefaultActionWatchdog(BaseWatchdog):
download_guid = event['guid']
download_event.set()
- cdp_client.on('Page.downloadWillBegin', on_download_will_begin, session_id=session_id) # type: ignore[attr-defined]
+ # TODO: fix this with download_watchdog.py
+ # cdp_client.on('Page.downloadWillBegin', on_download_will_begin, session_id=session_id) # type: ignore[attr-defined]
# Perform the click using CDP
try:
@@ -267,42 +270,42 @@ class DefaultActionWatchdog(BaseWatchdog):
)
# Handle download if expected
- if self.browser_session.browser_profile.downloads_path:
- try:
- # Wait for download to start (with timeout)
- await asyncio.wait_for(download_event.wait(), timeout=5.0)
-
- # Wait for download to complete
- download_complete = False
- for _ in range(60): # Wait up to 60 seconds
- try:
- # Check download progress
- response = await cdp_client.send.Page.getDownloadProgress(
- params={'guid': download_guid}, session_id=session_id
- )
- if response['state'] == 'completed':
- download_complete = True
- break
- elif response['state'] == 'canceled':
- self.logger.warning('Download was canceled')
- break
- except Exception:
- pass
- await asyncio.sleep(1)
-
- if download_complete and download_guid:
- self.logger.info('⬇️ Download completed via CDP')
- # Note: DownloadsWatchdog handles download tracking via events
- return f'download_{download_guid}' # Return guid as placeholder
- except TimeoutError:
- # No download triggered, normal click
- self.logger.debug('No download triggered within timeout.')
-
- # Wait for navigation/changes
- await asyncio.sleep(0.5)
- # Navigation is handled by NavigationWatchdog via events
-
- return download_path
+ # if self.browser_session.browser_profile.downloads_path:
+ # try:
+ # # Wait for download to start (with timeout)
+ # await asyncio.wait_for(download_event.wait(), timeout=5.0)
+
+ # # Wait for download to complete
+ # download_complete = False
+ # for _ in range(60): # Wait up to 60 seconds
+ # try:
+ # # Check download progress
+ # response = await cdp_client.send.Page.getDownloadProgress(
+ # params={'guid': download_guid}, session_id=session_id
+ # )
+ # if response['state'] == 'completed':
+ # download_complete = True
+ # break
+ # elif response['state'] == 'canceled':
+ # self.logger.warning('Download was canceled')
+ # break
+ # except Exception:
+ # pass
+ # await asyncio.sleep(1)
+
+ # if download_complete and download_guid:
+ # self.logger.info('⬇️ Download completed via CDP')
+ # # Note: DownloadsWatchdog handles download tracking via events
+ # return f'download_{download_guid}' # Return guid as placeholder
+ # except TimeoutError:
+ # # No download triggered, normal click
+ # self.logger.debug('No download triggered within timeout.')
+
+ # # Wait for navigation/changes
+ # await asyncio.sleep(0.5)
+ # # Navigation is handled by NavigationWatchdog via events
+
+ # return download_path
except Exception as e:
self.logger.warning(f'CDP click failed: {type(e).__name__}: {e}')
diff --git a/browser_use/browser/events.py b/browser_use/browser/events.py
index 279a48a75..4c945ecfd 100644
--- a/browser_use/browser/events.py
+++ b/browser_use/browser/events.py
@@ -1,18 +1,20 @@
"""Event definitions for browser communication."""
-from typing import Any, Literal
+from typing import Any, Generic, Literal
from bubus import BaseEvent
+from bubus.models import T_EventResultType
from pydantic import Field, field_validator
from browser_use.dom.views import EnhancedDOMTreeNode
+from typing_extensions import TypeVar
# ============================================================================
# Agent/Controller -> BrowserSession Events (High-level browser actions)
# ============================================================================
-class ElementSelectedEvent(BaseEvent):
+class ElementSelectedEvent(BaseEvent[T_EventResultType]):
"""An element was selected."""
node: EnhancedDOMTreeNode
@@ -53,7 +55,7 @@ class NavigateToUrlEvent(BaseEvent):
timeout_ms: int | None = None
-class ClickElementEvent(ElementSelectedEvent):
+class ClickElementEvent(ElementSelectedEvent[dict[str, str] | None]):
"""Click an element."""
node: 'EnhancedDOMTreeNode'
@@ -361,7 +363,7 @@ class AboutBlankDVDScreensaverShownEvent(BaseEvent):
# check that event names are valid and non-overlapping (naiively n^2 so it's pretty slow but ok for now, optimize when >20 events)
event_names = {
- name
+ name.split('[')[0]
for name in globals().keys()
if not name.startswith('_') and issubclass(globals()[name], BaseEvent) and name != 'BaseEvent'
}
diff --git a/browser_use/controller/views.py b/browser_use/controller/views.py
index 72fdd4f72..06edc7e53 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[dict[str, str] | None]):
+class ClickElementAction(BaseModel):
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 0e0e724eb..dd1776364 100644
--- a/browser_use/dom/views.py
+++ b/browser_use/dom/views.py
@@ -1,7 +1,7 @@
import hashlib
from dataclasses import asdict, dataclass, field
from enum import Enum
-from typing import TYPE_CHECKING, Any
+from typing import Any
from cdp_use.cdp.accessibility.commands import GetFullAXTreeReturns
from cdp_use.cdp.accessibility.types import AXPropertyName
@@ -340,17 +340,17 @@ class EnhancedDOMTreeNode:
async def create_cdp_session(self, browser_session):
"""Create a CDP session for this node's target.
-
+
Args:
browser_session: The BrowserSession to use for creating the CDP client
-
+
Returns:
CDPClient attached to this node's target
-
+
Note: Caller is responsible for cleanup using await cdp_client.stop()
"""
return await browser_session.create_cdp_session_for_node(self)
-
+
def get_all_children_text(self, max_depth: int = -1) -> str:
text_parts = []