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
changed time.sleep to asyncio.sleep
Gregor Žuničeb36c728a0a8
diff --git a/browser_use/agent/service.py b/browser_use/agent/service.pyindex 9b18bec96..fcb7a6893 100644--- a/browser_use/agent/service.py+++ b/browser_use/agent/service.py@@ -8,7 +8,6 @@ import loggingimport osimport platformimport textwrap-import timeimport uuidfrom io import BytesIOfrom pathlib import Path@@ -254,7 +253,7 @@ class Agent:self.consecutive_failures = 0except Exception as e:- result = self._handle_step_error(e)+ result = await self._handle_step_error(e)self._last_result = resultfinally:@@ -274,7 +273,7 @@ class Agent:if state:self._make_history_item(model_output, state, result)- def _handle_step_error(self, error: Exception) -> list[ActionResult]:+ async def _handle_step_error(self, error: Exception) -> list[ActionResult]:"""Handle all types of errors that can occur during a step"""include_trace = logger.isEnabledFor(logging.DEBUG)error_msg = AgentError.format_error(error, include_trace=include_trace)@@ -294,7 +293,7 @@ class Agent:self.consecutive_failures += 1elif isinstance(error, RateLimitError):logger.warning(f'{prefix}{error_msg}')- time.sleep(self.retry_delay)+ await asyncio.sleep(self.retry_delay)self.consecutive_failures += 1else:logger.error(f'{prefix}{error_msg}')@@ -465,6 +464,7 @@ class Agent:errors=self.history.errors(),))+if not self.injected_browser_context:await self.browser_context.close()