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
remove unecessary old navigation helper calls
Nick Sweeting93204d6f7e97
diff --git a/browser_use/browser/default_action_watchdog.py b/browser_use/browser/default_action_watchdog.pyindex dbbe5b0b8..4f870733e 100644--- a/browser_use/browser/default_action_watchdog.py+++ b/browser_use/browser/default_action_watchdog.py@@ -67,7 +67,7 @@ class DefaultActionWatchdog(BaseWatchdog):msg = f'Downloaded file to {download_path}'logger.info(f'πΎ {msg}')else:- msg = f'Clicked button with index {event.index}: {element_node.get_all_text_till_next_clickable_element(max_depth=2)}'+ msg = f'Clicked button with index {event.index}: {element_node.get_all_children_text(max_depth=2)}'logger.info(f'π±οΈ {msg}')logger.debug(f'Element xpath: {element_node.xpath}')@@ -286,8 +286,7 @@ class DefaultActionWatchdog(BaseWatchdog):if download_complete and download_guid:logger.info(f'β¬οΈ Download completed via CDP')- # Track the download (note: CDP doesn't give us filename directly)- self.browser_session._downloaded_files.append(f'download_{download_guid}')+ # Note: DownloadsWatchdog handles download tracking via eventsreturn f'download_{download_guid}' # Return guid as placeholderexcept asyncio.TimeoutError:# No download triggered, normal click@@ -295,7 +294,7 @@ class DefaultActionWatchdog(BaseWatchdog):# Wait for navigation/changesawait asyncio.sleep(0.5)- await self.browser_session._check_and_handle_navigation(page)+ # Navigation is handled by NavigationWatchdog via eventsreturn download_path@@ -317,7 +316,7 @@ class DefaultActionWatchdog(BaseWatchdog):session_id=session_id,)await asyncio.sleep(0.5)- await self.browser_session._check_and_handle_navigation(page)+ # Navigation is handled by NavigationWatchdog via eventsreturn Noneexcept Exception as js_e:logger.error(f'CDP JavaScript click also failed: {js_e}')@@ -518,14 +517,14 @@ class DefaultActionWatchdog(BaseWatchdog):# Enable required domains on this sessionawait cdp_client.send.DOM.enable(session_id=session_id)await cdp_client.send.Runtime.enable(session_id=session_id)- await cdp_client.send.Input.enable(session_id=session_id)+ # Note: Input domain doesn't have an enable methodreturn session_id- # If frame not found in targets, use main page session- logger.debug(f'Frame {element_node.frame_id} not found in targets, using main session')- except Exception as e:- logger.debug(f'Error getting frame session: {e}, using main session')+ # If frame not found in targets, use main page session+ logger.debug(f'Frame {element_node.frame_id} not found in targets, using main session')+ except Exception as e:+ logger.debug(f'Error getting frame session: {e}, using main session')# Use main page sessionreturn await self.browser_session.get_current_page_cdp_session_id()@@ -556,8 +555,7 @@ class DefaultActionWatchdog(BaseWatchdog):# Wait for navigationawait asyncio.sleep(0.5)- page = await self.browser_session.get_current_page()- await self.browser_session._check_and_handle_navigation(page)+ # Navigation is handled by NavigationWatchdog via eventslogger.info(f'π Navigated back to {entries[current_index - 1]["url"]}')except Exception as e:@@ -594,8 +592,7 @@ class DefaultActionWatchdog(BaseWatchdog):# Wait for navigationawait asyncio.sleep(0.5)- page = await self.browser_session.get_current_page()- await self.browser_session._check_and_handle_navigation(page)+ # Navigation is handled by NavigationWatchdog via eventslogger.info(f'π Navigated forward to {entries[current_index + 1]["url"]}')except Exception as e:@@ -618,8 +615,7 @@ class DefaultActionWatchdog(BaseWatchdog):# Wait for reloadawait asyncio.sleep(1.0)- page = await self.browser_session.get_current_page()- await self.browser_session._check_and_handle_navigation(page)+ # Navigation is handled by NavigationWatchdog via eventslogger.info('π Page refreshed')except Exception as e:diff --git a/browser_use/browser/session.py b/browser_use/browser/session.pyindex 87b7cda6c..721711083 100644--- a/browser_use/browser/session.py+++ b/browser_use/browser/session.py@@ -1,9 +1,13 @@"""Event-driven browser session with backwards compatibility."""import asyncio+import atexit+import loggingimport os+import shutil+from functools import wrapsfrom pathlib import Path-from typing import Any, Self+from typing import Any, Self, Neverfrom browser_use.config import CONFIGfrom browser_use.observability import observe_debug@@ -2074,9 +2078,8 @@ class BrowserSession(BaseModel):await download.save_as(download_path)self.logger.info(f'β¬οΈ Downloaded file to: {download_path}')- # Track the downloaded file in the session- self._downloaded_files.append(download_path)- self.logger.info(f'π Added download to session tracking (total: {len(self._downloaded_files)} files)')+ # Downloads are tracked via the filesystem in the session's unique downloads directory+ self.logger.info(f'π Download completed: {download_path}')return download_pathexcept Exception: