Automate browser based workflows with AI
Python aiapiautomationbrowserbrowser-automationcomputergptllmplaywrightpowerautomatepuppeteerpythonrpaseleniumvisionworkflow
shu/fix cdp connect with browser path (#2057)
Shuchang Zheng3fc6e2532ff4
diff --git a/skyvern/agent/agent.py b/skyvern/agent/agent.pyindex a753dabc3..3e88aa2af 100644--- a/skyvern/agent/agent.py+++ b/skyvern/agent/agent.py@@ -44,10 +44,10 @@ class SkyvernAgent:# TODO validate browser_path# Supported Browsers: Google Chrome, Brave Browser, Microsoft Edge, Firefoxif "Chrome" in browser_path or "Brave" in browser_path or "Edge" in browser_path:- result = subprocess.run(- ["/Applications/Google Chrome.app/Contents/MacOS/Google Chrome", "--remote-debugging-port=9222"]+ self.browser_process = subprocess.Popen(+ [browser_path, "--remote-debugging-port=9222"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)- if result.returncode != 0:+ if self.browser_process.poll() is not None:raise Exception(f"Failed to open browser. browser_path: {browser_path}")self.cdp_url = "http://127.0.0.1:9222"diff --git a/skyvern/webeye/browser_factory.py b/skyvern/webeye/browser_factory.pyindex 86f886e77..c39d240b1 100644--- a/skyvern/webeye/browser_factory.py+++ b/skyvern/webeye/browser_factory.py@@ -417,7 +417,13 @@ class BrowserState:pages = self.browser_context.pagesfor page in pages:if page != cur_page:- await page.close()+ try:+ async with asyncio.timeout(2):+ await page.close()+ except asyncio.TimeoutError:+ LOG.warning("Timeout to close the page. Skip closing the page", url=page.url)+ except Exception:+ LOG.exception("Error while closing the page", url=page.url)async def check_and_fix_state(self,