Automate browser based workflows with AI
Python aiapiautomationbrowserbrowser-automationcomputergptllmplaywrightpowerautomatepuppeteerpythonrpaseleniumvisionworkflow
auto close when page number exceeds (#4101)
LawyZheng1fff8a2ac6a9
diff --git a/skyvern/config.py b/skyvern/config.pyindex 0181e1f11..e1d5aa8ba 100644--- a/skyvern/config.py+++ b/skyvern/config.py@@ -119,6 +119,7 @@ class Settings(BaseSettings):BROWSER_HEIGHT: int = 1080BROWSER_POLICY_FILE: str = "/etc/chromium/policies/managed/policies.json"BROWSER_LOGS_ENABLED: bool = True+ BROWSER_MAX_PAGES_NUMBER: int = 10# Add extension folders name here to load extension in your browserEXTENSIONS_BASE_PATH: str = "./extensions"diff --git a/skyvern/webeye/browser_factory.py b/skyvern/webeye/browser_factory.pyindex 36055a229..42a186856 100644--- a/skyvern/webeye/browser_factory.py+++ b/skyvern/webeye/browser_factory.py@@ -781,14 +781,14 @@ class BrowserState:await self.set_working_page(last_page, len(pages) - 1)return last_page- async def list_valid_pages(self) -> list[Page]:- # List all valid pages(blank page, and http/https page) in the browser context+ async def list_valid_pages(self, max_pages: int = settings.BROWSER_MAX_PAGES_NUMBER) -> list[Page]:+ # List all valid pages(blank page, and http/https page) in the browser context, up to max_pages# MSEdge CDP bug(?)# when using CDP connect to a MSEdge, the download hub will be included in the context.pagesif self.browser_context is None:return []- return [+ pages = [http_pagefor http_page in self.browser_context.pagesif (@@ -798,6 +798,21 @@ class BrowserState:)]+ if max_pages <= 0 or len(pages) <= max_pages:+ return pages++ reserved_pages = pages[-max_pages:]++ closing_pages = pages[: len(pages) - max_pages]+ LOG.warning(+ "The page number exceeds the limit, closing the oldest pages. It might cause the video missing",+ closing_pages=closing_pages,+ )+ for page in closing_pages:+ await page.close()++ return reserved_pages+async def validate_browser_context(self, page: Page) -> bool:# validate the contenttry: