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
cleaner logging slightly
Nick Sweeting78ee73c949a0
diff --git a/browser_use/agent/service.py b/browser_use/agent/service.pyindex ffb295ec9..15e9288bc 100644--- a/browser_use/agent/service.py+++ b/browser_use/agent/service.py@@ -1580,15 +1580,15 @@ class Agent(Generic[Context, AgentStructuredOutput]):# Get action name from the action modelaction_data = action.model_dump(exclude_unset=True)action_name = next(iter(action_data.keys())) if action_data else 'unknown'- action_params = getattr(action, action_name, '') or str(action.model_dump(mode='json'))[:56].replace(+ action_params = getattr(action, action_name, '') or str(action.model_dump(mode='json'))[:140].replace('"', '').replace('{', '').replace('}', '').replace("'", '').strip().strip(',')# Ensure action_params is always a string before checking lengthaction_params = str(action_params)- action_params = f'{action_params[:50]}...' if len(action_params) > 54 else action_params+ action_params = f'{action_params[:122]}...' if len(action_params) > 128 else action_paramstime_start = time.time()- self.logger.info(f'π¦Ύ Executing action {i + 1}/{total_actions}: {cyan}{action_name}({action_params}){reset}...')+ self.logger.info(f'π¦Ύ {cyan}[ACTION {i + 1}/{total_actions}] {action_name}({action_params})... {reset}')result = await self.controller.act(action=action,diff --git a/browser_use/browser/session.py b/browser_use/browser/session.pyindex 3e1e22e85..ef9368a84 100644--- a/browser_use/browser/session.py+++ b/browser_use/browser/session.py@@ -574,13 +574,13 @@ class BrowserSession(BaseModel):self.logger.debug(f'π AgentFocusChangedEvent received: tab_index={event.tab_index}, url={event.url}')# Clear cached DOM state since focus changed- self.logger.debug('π Clearing DOM cache...')+ # self.logger.debug('π Clearing DOM cache...')if self._dom_watchdog:self._dom_watchdog.clear_cache()- self.logger.debug('π Cleared DOM cache after focus change')+ # self.logger.debug('π Cleared DOM cache after focus change')# Clear cached browser state- self.logger.debug('π Clearing cached browser state...')+ # self.logger.debug('π Clearing cached browser state...')self._cached_browser_state_summary = Noneself._cached_selector_map.clear()self.logger.debug('π Cached browser state cleared')@@ -592,7 +592,7 @@ class BrowserSession(BaseModel):self.logger.debug(f'π Got {len(targets)} targets')if 0 <= event.tab_index < len(targets):target_id = targets[event.tab_index]['targetId']- self.logger.debug(f'π Getting CDP session for target {target_id}...')+ # self.logger.debug(f'π Getting CDP session for target {target_id}...')self.agent_focus = await self.get_or_create_cdp_session(target_id, focus=True)self.logger.debug(f'π Updated agent focus to tab {event.tab_index} (target {target_id})')@@ -607,14 +607,15 @@ class BrowserSession(BaseModel):timeout=2.0,)if test_result.get('result', {}).get('value') == 2:- self.logger.debug('π β Browser is responsive after focus change')+ # self.logger.debug('π β Browser is responsive after focus change')+ passelse:raise Exception('β Failed to execute test JS expression with Page.evaluate')except Exception as e:self.logger.error(f'π β Page appears crashed after focus change: {e}')raise- self.logger.debug('π AgentFocusChangedEvent handler completed successfully')+ # self.logger.debug('π AgentFocusChangedEvent handler completed successfully')async def on_FileDownloadedEvent(self, event: FileDownloadedEvent) -> None:"""Track downloaded files during this session."""