From c084764373b1ce7234ecd845ec82ff2319e68a23 Mon Sep 17 00:00:00 2001 From: LawyZheng Date: Wed, 6 Nov 2024 16:24:44 +0800 Subject: [PATCH] increase timeout for scrolling (#1145) --- skyvern/constants.py | 1 + skyvern/webeye/scraper/scraper.py | 8 ++++---- skyvern/webeye/utils/page.py | 10 +++++++--- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/skyvern/constants.py b/skyvern/constants.py index 85a2ec762..1794053c1 100644 --- a/skyvern/constants.py +++ b/skyvern/constants.py @@ -8,6 +8,7 @@ INPUT_TEXT_TIMEOUT = 120000 # 2 minutes PAGE_CONTENT_TIMEOUT = 300 # 5 mins +BUILDING_ELEMENT_TREE_TIMEOUT_MS = 60 * 1000 # 1 minute BROWSER_CLOSE_TIMEOUT = 180 # 3 minute BROWSER_DOWNLOAD_TIMEOUT = 600 # 10 minute diff --git a/skyvern/webeye/scraper/scraper.py b/skyvern/webeye/scraper/scraper.py index 2200a2c2e..814257446 100644 --- a/skyvern/webeye/scraper/scraper.py +++ b/skyvern/webeye/scraper/scraper.py @@ -9,7 +9,7 @@ from playwright.async_api import Frame, Locator, Page from pydantic import BaseModel -from skyvern.constants import SKYVERN_DIR, SKYVERN_ID_ATTR +from skyvern.constants import BUILDING_ELEMENT_TREE_TIMEOUT_MS, SKYVERN_DIR, SKYVERN_ID_ATTR from skyvern.exceptions import FailedToTakeScreenshot, UnknownElementTreeFormat from skyvern.forge.sdk.api.crypto import calculate_sha256 from skyvern.forge.sdk.settings_manager import SettingsManager @@ -419,7 +419,7 @@ async def get_interactable_element_tree_in_frame( await SkyvernFrame.evaluate(frame=frame, expression=JS_FUNCTION_DEFS) frame_elements, frame_element_tree = await SkyvernFrame.evaluate( - frame=frame, expression=frame_js_script, timeout_ms=60 * 1000 + frame=frame, expression=frame_js_script, timeout_ms=BUILDING_ELEMENT_TREE_TIMEOUT_MS ) if len(frame.child_frames) > 0: @@ -455,7 +455,7 @@ async def get_interactable_element_tree( await SkyvernFrame.evaluate(frame=page, expression=JS_FUNCTION_DEFS) main_frame_js_script = "() => buildTreeFromBody()" elements, element_tree = await SkyvernFrame.evaluate( - frame=page, expression=main_frame_js_script, timeout_ms=60 * 1000 + frame=page, expression=main_frame_js_script, timeout_ms=BUILDING_ELEMENT_TREE_TIMEOUT_MS ) if len(page.main_frame.child_frames) > 0: @@ -486,7 +486,7 @@ async def get_incremental_element_tree( js_script = "() => getIncrementElements()" incremental_elements, incremental_tree = await SkyvernFrame.evaluate( - frame=frame, expression=js_script, timeout_ms=60 * 1000 + frame=frame, expression=js_script, timeout_ms=BUILDING_ELEMENT_TREE_TIMEOUT_MS ) # we listen the incremental elements seperated by frames, so all elements will be in the same SkyvernFrame self.id_to_css_dict, self.id_to_element_dict, _, _, _ = build_element_dict(incremental_elements) diff --git a/skyvern/webeye/utils/page.py b/skyvern/webeye/utils/page.py index b91e0ae77..596f4aba1 100644 --- a/skyvern/webeye/utils/page.py +++ b/skyvern/webeye/utils/page.py @@ -8,7 +8,7 @@ from playwright._impl._errors import TimeoutError from playwright.async_api import ElementHandle, Frame, Page -from skyvern.constants import PAGE_CONTENT_TIMEOUT, SKYVERN_DIR +from skyvern.constants import BUILDING_ELEMENT_TREE_TIMEOUT_MS, PAGE_CONTENT_TIMEOUT, SKYVERN_DIR from skyvern.exceptions import FailedToTakeScreenshot from skyvern.forge.sdk.settings_manager import SettingsManager @@ -190,7 +190,9 @@ async def scroll_to_top(self, draw_boxes: bool) -> float: :return: Screenshot of the page. """ js_script = f"() => scrollToTop({str(draw_boxes).lower()})" - scroll_y_px = await self.evaluate(frame=self.frame, expression=js_script) + scroll_y_px = await self.evaluate( + frame=self.frame, expression=js_script, timeout_ms=BUILDING_ELEMENT_TREE_TIMEOUT_MS + ) return scroll_y_px async def scroll_to_next_page(self, draw_boxes: bool) -> float: @@ -201,7 +203,9 @@ async def scroll_to_next_page(self, draw_boxes: bool) -> float: :return: Screenshot of the page. """ js_script = f"() => scrollToNextPage({str(draw_boxes).lower()})" - scroll_y_px = await self.evaluate(frame=self.frame, expression=js_script) + scroll_y_px = await self.evaluate( + frame=self.frame, expression=js_script, timeout_ms=BUILDING_ELEMENT_TREE_TIMEOUT_MS + ) return scroll_y_px async def remove_bounding_boxes(self) -> None: