Skip to content

Commit

Permalink
increase timeout for scrolling (#1145)
Browse files Browse the repository at this point in the history
  • Loading branch information
LawyZheng authored Nov 6, 2024
1 parent 47445a2 commit c084764
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
1 change: 1 addition & 0 deletions skyvern/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 4 additions & 4 deletions skyvern/webeye/scraper/scraper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down
10 changes: 7 additions & 3 deletions skyvern/webeye/utils/page.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down

0 comments on commit c084764

Please sign in to comment.