From 3a86bc9ae554b303e90f1d74c879d05832189150 Mon Sep 17 00:00:00 2001 From: LawyZheng Date: Tue, 23 Jul 2024 12:46:50 +0800 Subject: [PATCH] recreate browser and try again when navigation network error --- skyvern/webeye/browser_factory.py | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/skyvern/webeye/browser_factory.py b/skyvern/webeye/browser_factory.py index ac76896452..f159e0cf26 100644 --- a/skyvern/webeye/browser_factory.py +++ b/skyvern/webeye/browser_factory.py @@ -235,7 +235,10 @@ async def check_and_fix_state( ) await asyncio.sleep(5) except Error as playright_error: - LOG.exception(f"Error while navigating to url: {str(playright_error)}") + LOG.warning( + f"Error while navigating to url: {str(playright_error)}", + exc_info=True, + ) raise FailedToNavigateToUrl(url=url, error_message=str(playright_error)) success = True LOG.info(f"Successfully went to {url}") @@ -265,20 +268,30 @@ async def get_or_create_page( if self.page is not None: return self.page - await self.check_and_fix_state(url=url, proxy_location=proxy_location, task_id=task_id) + try: + await self.check_and_fix_state(url=url, proxy_location=proxy_location, task_id=task_id) + except Exception as e: + error_message = str(e) + if "net::ERR" not in error_message: + raise e + await self.close_current_open_page() + await self.check_and_fix_state(url=url, proxy_location=proxy_location, task_id=task_id) assert self.page is not None if not await BrowserContextFactory.validate_browser_context(self.page): - await self._close_all_other_pages() - if self.browser_context is not None: - await self.browser_context.close() - self.browser_context = None - self.page = None + await self.close_current_open_page() await self.check_and_fix_state(url=url, proxy_location=proxy_location, task_id=task_id) assert self.page is not None return self.page + async def close_current_open_page(self) -> None: + await self._close_all_other_pages() + if self.browser_context is not None: + await self.browser_context.close() + self.browser_context = None + self.page = None + async def stop_page_loading(self) -> None: page = self.__assert_page() try: