Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

try to fix navigation error #630

Merged
merged 1 commit into from
Jul 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 20 additions & 7 deletions skyvern/webeye/browser_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand Down Expand Up @@ -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:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider refining the exception handling in the retry mechanism to specifically catch navigation-related exceptions (e.g., playwright.async_api.Error) instead of a generic Exception. This would prevent the retry logic from being triggered by unrelated exceptions and improve the robustness of the error handling.

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:
Expand Down
Loading