Automate browser based workflows with AI
Python aiapiautomationbrowserbrowser-automationcomputergptllmplaywrightpowerautomatepuppeteerpythonrpaseleniumvisionworkflow
fix block screenshot bug (#3361)
LawyZheng9413958f4b36
diff --git a/skyvern/forge/sdk/workflow/models/block.py b/skyvern/forge/sdk/workflow/models/block.pyindex ce28ed619..54231dedf 100644--- a/skyvern/forge/sdk/workflow/models/block.py+++ b/skyvern/forge/sdk/workflow/models/block.py@@ -581,8 +581,21 @@ class BaseTaskBlock(Block):browser_state = await app.BROWSER_MANAGER.get_or_create_for_workflow_run(workflow_run=workflow_run, url=self.url, browser_session_id=browser_session_id)- # assert that the browser state is not None, otherwise we can't go through typing- assert browser_state is not None+ except Exception as e:+ LOG.exception(+ "Failed to get browser state for first task",+ task_id=task.task_id,+ workflow_run_id=workflow_run_id,+ )+ # Make sure the task is marked as failed in the database before raising the exception+ await app.DATABASE.update_task(+ task.task_id,+ status=TaskStatus.failed,+ organization_id=workflow_run.organization_id,+ failure_reason=str(e),+ )+ raise e+ try:# add screenshot artifact for the first taskscreenshot = await browser_state.take_fullpage_screenshot(use_playwright_fullpage=app.EXPERIMENTATION_PROVIDER.is_feature_enabled_cached(@@ -597,20 +610,13 @@ class BaseTaskBlock(Block):artifact_type=ArtifactType.SCREENSHOT_LLM,data=screenshot,)- except Exception as e:- LOG.exception(- "Failed to get browser state for first task",+ except Exception:+ LOG.warning(+ "Failed to take screenshot for first task",task_id=task.task_id,workflow_run_id=workflow_run_id,+ exc_info=True,)- # Make sure the task is marked as failed in the database before raising the exception- await app.DATABASE.update_task(- task.task_id,- status=TaskStatus.failed,- organization_id=workflow_run.organization_id,- failure_reason=str(e),- )- raise eelse:# if not the first task block, need to navigate manuallybrowser_state = app.BROWSER_MANAGER.get_for_workflow_run(workflow_run_id=workflow_run_id)diff --git a/skyvern/webeye/utils/page.py b/skyvern/webeye/utils/page.pyindex e876c0caa..f17e235ee 100644--- a/skyvern/webeye/utils/page.py+++ b/skyvern/webeye/utils/page.py@@ -310,7 +310,7 @@ class SkyvernFrame:)finally:if x is not None and y is not None:- await skyvern_frame.scroll_to_x_y(x, y)+ await skyvern_frame.safe_scroll_to_x_y(x, y)@staticmethod@TraceManager.traced_async(ignore_inputs=["page"])@@ -366,6 +366,12 @@ class SkyvernFrame:js_script = "([x, y]) => scrollToXY(x, y)"return await self.evaluate(frame=self.frame, expression=js_script, arg=[x, y])+ async def safe_scroll_to_x_y(self, x: int, y: int) -> None:+ try:+ await self.scroll_to_x_y(x, y)+ except Exception:+ LOG.warning("Failed to scroll to x, y, ignore it", x=x, y=y, exc_info=True)+async def scroll_to_element_bottom(self, element: ElementHandle, page_by_page: bool = False) -> None:js_script = "([element, page_by_page]) => scrollToElementBottom(element, page_by_page)"return await self.evaluate(frame=self.frame, expression=js_script, arg=[element, page_by_page])