From 0ed55ad8bcd58236ea0ae6958d0534c30a8c5ea2 Mon Sep 17 00:00:00 2001 From: LawyZheng Date: Wed, 26 Nov 2025 15:05:37 +0800 Subject: [PATCH] safely close the tab (#4103) --- skyvern/constants.py | 1 + skyvern/webeye/browser_factory.py | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/skyvern/constants.py b/skyvern/constants.py index 125d4fca..3c64afa0 100644 --- a/skyvern/constants.py +++ b/skyvern/constants.py @@ -8,6 +8,7 @@ REPO_ROOT_DIR = SKYVERN_DIR.parent INPUT_TEXT_TIMEOUT = 120000 # 2 minutes PAGE_CONTENT_TIMEOUT = 300 # 5 mins +BROWSER_PAGE_CLOSE_TIMEOUT = 5 # 5 seconds BROWSER_CLOSE_TIMEOUT = 180 # 3 minute BROWSER_DOWNLOAD_MAX_WAIT_TIME = 120 # 2 minute BROWSER_DOWNLOAD_TIMEOUT = 600 # 10 minute diff --git a/skyvern/webeye/browser_factory.py b/skyvern/webeye/browser_factory.py index e8932eb3..92e91f5d 100644 --- a/skyvern/webeye/browser_factory.py +++ b/skyvern/webeye/browser_factory.py @@ -23,7 +23,13 @@ from playwright.async_api import BrowserContext, ConsoleMessage, Download, Page, from pydantic import BaseModel, PrivateAttr from skyvern.config import settings -from skyvern.constants import BROWSER_CLOSE_TIMEOUT, BROWSER_DOWNLOAD_TIMEOUT, NAVIGATION_MAX_RETRY_TIME, SKYVERN_DIR +from skyvern.constants import ( + BROWSER_CLOSE_TIMEOUT, + BROWSER_DOWNLOAD_TIMEOUT, + BROWSER_PAGE_CLOSE_TIMEOUT, + NAVIGATION_MAX_RETRY_TIME, + SKYVERN_DIR, +) from skyvern.exceptions import ( EmptyBrowserContext, FailedToNavigateToUrl, @@ -809,7 +815,11 @@ class BrowserState: closing_pages=closing_pages, ) for page in closing_pages: - await page.close() + try: + async with asyncio.timeout(BROWSER_PAGE_CLOSE_TIMEOUT): + await page.close() + except Exception: + LOG.warning("Error while closing the page", exc_info=True) return reserved_pages