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
add some newlines in logging output to visually separate steps
Nick Sweeting1c7eb2b8492b
diff --git a/browser_use/agent/service.py b/browser_use/agent/service.pyindex 574dc586d..170030bcf 100644--- a/browser_use/agent/service.py+++ b/browser_use/agent/service.py@@ -90,7 +90,7 @@ def log_response(response: AgentOutput, registry=None, logger=None) -> None:logger.info(f'{emoji} Eval: {response.current_state.evaluation_previous_goal}')logger.info(f'🧠 Memory: {response.current_state.memory}')- logger.info(f'🎯 Next goal: {response.current_state.next_goal}')+ logger.info(f'🎯 Next goal: {response.current_state.next_goal}\n')Context = TypeVar('Context')@@ -99,7 +99,7 @@ AgentHookFunc = Callable[['Agent'], Awaitable[None]]class Agent(Generic[Context]):- @time_execution_sync('--init (agent)')+ @time_execution_sync('--init')def __init__(self,task: str,@@ -464,7 +464,7 @@ class Agent(Generic[Context]):if source_override is not None:source = source_override- self.logger.debug(f'Version: {version}, Source: {source}')+ # self.logger.debug(f'Version: {version}, Source: {source}') # moved later to _log_agent_run so that people are more likely to include it in copy-pasted support ticket logsself.version = versionself.source = source@@ -790,7 +790,7 @@ class Agent(Generic[Context]):raise InterruptedError# @observe(name='agent.step', ignore_output=True, ignore_input=True)- @time_execution_async('--step (agent)')+ @time_execution_async('--step')async def step(self, step_info: AgentStepInfo | None = None) -> None:"""Execute one step of the task"""browser_state_summary = None@@ -970,7 +970,7 @@ class Agent(Generic[Context]):# Log step completion summaryself._log_step_completion_summary(step_start_time, result)- @time_execution_async('--handle_step_error (agent)')+ @time_execution_async('--handle_step_error')async def _handle_step_error(self, error: Exception) -> list[ActionResult]:"""Handle all types of errors that can occur during a step"""include_trace = self.logger.isEnabledFor(logging.DEBUG)@@ -1059,7 +1059,7 @@ class Agent(Generic[Context]):else:return input_messages- @time_execution_async('--get_next_action (agent)')+ @time_execution_async('--get_next_action')async def get_next_action(self, input_messages: list[BaseMessage]) -> AgentOutput:"""Get next action from LLM based on current state"""input_messages = self._convert_input_messages(input_messages)@@ -1147,12 +1147,13 @@ class Agent(Generic[Context]):"""Log the agent run"""self.logger.info(f'🚀 Starting task: {self.task}')- self.logger.debug(f'Version: {self.version}, Source: {self.source}')+ self.logger.debug(f'🤖 Browser-Use Version: v{self.version} ({self.source})')def _log_step_context(self, current_page, browser_state_summary) -> None:"""Log step context information"""url_short = current_page.url[:50] + '...' if len(current_page.url) > 50 else current_page.urlinteractive_count = len(browser_state_summary.selector_map) if browser_state_summary else 0+ print(file=sys.stderr) # just to visually separate stuff nicelyself.logger.info(f'📍 Step {self.state.n_steps}: Evaluating page with {interactive_count} interactive elements on: {url_short}')@@ -1192,9 +1193,9 @@ class Agent(Generic[Context]):# Create summary based on single vs multi-actionif action_count == 1:- self.logger.info(f'⚡️ Decided next action: {action_name}{param_str}')+ self.logger.info(f'☝️ Decided next action: {action_name}{param_str}')else:- summary_lines = [f'⚡️ Decided next {action_count} multi-actions:']+ summary_lines = [f'✌️ Decided next {action_count} multi-actions:']for i, detail in enumerate(action_details):summary_lines.append(f' {i + 1}. {detail}')self.logger.info('\n'.join(summary_lines))@@ -1320,7 +1321,7 @@ class Agent(Generic[Context]):return False, False# @observe(name='agent.run', ignore_output=True)- @time_execution_async('--run (agent)')+ @time_execution_async('--run')async def run(self, max_steps: int = 100, on_step_start: AgentHookFunc | None = None, on_step_end: AgentHookFunc | None = None) -> AgentHistoryList:@@ -1511,7 +1512,8 @@ class Agent(Generic[Context]):# 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'- self.logger.info(f'☑️ Executed action {i + 1}/{len(actions)}: {action_name}')+ action_params = getattr(action, action_name, '')+ self.logger.info(f'☑️ Executed action {i + 1}/{len(actions)}: {action_name}({action_params})')if results[-1].is_done or results[-1].error or i == len(actions) - 1:breakdiff --git a/browser_use/browser/session.py b/browser_use/browser/session.pyindex 973f512ad..2e70f0bdd 100644--- a/browser_use/browser/session.py+++ b/browser_use/browser/session.py@@ -1292,11 +1292,11 @@ class BrowserSession(BaseModel):unique_filename = await self._get_unique_filename(self.browser_profile.downloads_path, suggested_filename)download_path = os.path.join(self.browser_profile.downloads_path, unique_filename)await download.save_as(download_path)- self.logger.info(f'⬇️ Download triggered. Saved file to: {download_path}')+ self.logger.info(f'⬇️ Downloaded file to: {download_path}')return download_pathexcept Exception:# If no download is triggered, treat as normal click- self.logger.debug('No download triggered within timeout. Checking navigation...')+ # self.logger.debug('No download triggered within timeout. Checking navigation...')await page.wait_for_load_state()await self._check_and_handle_navigation(page)else:@@ -1798,14 +1798,16 @@ class BrowserSession(BaseModel):bytes_used = Nonetab_idx = self.tabs.index(page)+ extra_delay = ''+ if remaining > 0:+ extra_delay = f', waiting +{remaining:.2f}s for all frames to finish'+if bytes_used is not None:self.logger.info(- f'➡️ Page navigation [{tab_idx}]{_log_pretty_url(page.url, 40)} used {bytes_used / 1024:.1f} KB in {elapsed:.2f}s, waiting +{remaining:.2f}s for all frames to finish'+ f'➡️ Page navigation [{tab_idx}]{_log_pretty_url(page.url, 40)} used {bytes_used / 1024:.1f} KB in {elapsed:.2f}s{extra_delay}')else:- self.logger.info(- f'➡️ Page navigation [{tab_idx}]{_log_pretty_url(page.url, 40)} took {elapsed:.2f}s, waiting +{remaining:.2f}s for all frames to finish'- )+ self.logger.info(f'➡️ Page navigation [{tab_idx}]{_log_pretty_url(page.url, 40)} took {elapsed:.2f}s{extra_delay}')# Sleep remaining time if neededif remaining > 0: