Open-source Python library for AI browser agents, plus Browser Use Cloud: stealth browsers and a hosted agent API.
Python ai-agentsai-toolsbrowser-agentbrowser-automationbrowser-usecdpcloud-browsercomputer-useheadless-browserllmmcpplaywrightpythonremote-browserstealth-browserweb-automationweb-scraping
fix variable scoping in downloads watchdog
Nick Sweetingf08001581f28
diff --git a/browser_use/browser/session.py b/browser_use/browser/session.pyindex ae614739d..ae5a983d4 100644--- a/browser_use/browser/session.py+++ b/browser_use/browser/session.py@@ -1916,7 +1916,9 @@ class BrowserSession(BaseModel):)object_id = result.get('object', {}).get('objectId')if not object_id:- raise ValueError(f'Could not find #{node.element_index} backendNodeId={node.backend_node_id} in target_id={cdp_session.target_id}')+ raise ValueError(+ f'Could not find #{node.element_index} backendNodeId={node.backend_node_id} in target_id={cdp_session.target_id}'+ )return cdp_sessionexcept (ValueError, Exception) as e:# Fall back to main session if frame not found@@ -1931,7 +1933,9 @@ class BrowserSession(BaseModel):)object_id = result.get('object', {}).get('objectId')if not object_id:- raise ValueError(f'Could not find #{node.element_index} backendNodeId={node.backend_node_id} in target_id={cdp_session.target_id}')+ raise ValueError(+ f'Could not find #{node.element_index} backendNodeId={node.backend_node_id} in target_id={cdp_session.target_id}'+ )except Exception as e:self.logger.debug(f'Failed to get CDP client for target {node.target_id}: {e}, using main session')diff --git a/browser_use/browser/watchdogs/downloads_watchdog.py b/browser_use/browser/watchdogs/downloads_watchdog.pyindex 026f66c35..ea838f7a5 100644--- a/browser_use/browser/watchdogs/downloads_watchdog.py+++ b/browser_use/browser/watchdogs/downloads_watchdog.py@@ -228,7 +228,7 @@ class DownloadsWatchdog(BaseWatchdog):self.browser_session.browser_profile.downloads_pathor f'{tempfile.gettempdir()}/browser_use_downloads.{str(self.browser_session.id)[-4:]}')-+# Initialize variables that may be used outside try blocksunique_filename = Nonefile_size = 0@@ -236,7 +236,7 @@ class DownloadsWatchdog(BaseWatchdog):download_result = Nonedownload_url = event.get('url', '')suggested_filename = event.get('suggestedFilename', 'download')-+try:guid = event.get('guid', '')@@ -313,7 +313,7 @@ class DownloadsWatchdog(BaseWatchdog):self.logger.debug(f'[DownloadsWatchdog] ✅ Downloaded and saved file: {final_path} ({file_size} bytes)')expected_path = final_path-+# Determine file type from extensionfile_ext = expected_path.suffix.lower().lstrip('.')file_type = file_ext if file_ext else None