Skip to content

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

Enhance logging: include 'google_genai' in logging configuration and improve attachment logging format. Log task duration on completion.

Magnus Müller7d53f108c795
diff --git a/browser_use/agent/service.py b/browser_use/agent/service.py
index 9d64ff4bb..b604f3e93 100644
--- a/browser_use/agent/service.py
+++ b/browser_use/agent/service.py
@@ -802,8 +802,9 @@ class Agent(Generic[Context, AgentStructuredOutput]):
# Red color for failure
self.logger.info(f'📄 \033[31m Result:\033[0m \n{self.state.last_result[-1].extracted_content}\n\n')
if self.state.last_result[-1].attachments:
+ total_attachments = len(self.state.last_result[-1].attachments)
for i, file_path in enumerate(self.state.last_result[-1].attachments):
- self.logger.info(f'👉 Attachment {i + 1}: {file_path}')
+ self.logger.info(f'👉 Attachment {i + 1 if total_attachments > 1 else ""}: {file_path}')
async def _handle_step_error(self, error: Exception) -> None:
"""Handle all types of errors that can occur during a step"""
@@ -1638,10 +1639,12 @@ class Agent(Generic[Context, AgentStructuredOutput]):
async def log_completion(self) -> None:
"""Log the completion of the task"""
+ self._task_end_time = time.time()
+ self._task_duration = self._task_end_time - self._task_start_time
if self.history.is_successful():
- self.logger.info('✅ Task completed successfully')
+ self.logger.info(f'✅ Task completed successfully in {self._task_duration:.2f}s')
else:
- self.logger.info('❌ Task completed without success')
+ self.logger.info(f'❌ Task completed without success in {self._task_duration:.2f}s')
async def rerun_history(
self,
diff --git a/browser_use/logging_config.py b/browser_use/logging_config.py
index 1295d4214..b546956a7 100644
--- a/browser_use/logging_config.py
+++ b/browser_use/logging_config.py
@@ -208,6 +208,7 @@ def setup_logging(stream=None, log_level=None, force_setup=False):
'trafilatura',
'groq',
'portalocker',
+ 'google_genai',
'portalocker.utils',
'websockets', # General websockets (but not websockets.client which we need)
]