From e12282187836af563705aed11795fe3ca43f0ed1 Mon Sep 17 00:00:00 2001 From: Shuchang Zheng Date: Thu, 27 Mar 2025 00:44:49 -0700 Subject: [PATCH] add safeWindowScroll function in js (#2029) --- skyvern/webeye/scraper/domUtils.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/skyvern/webeye/scraper/domUtils.js b/skyvern/webeye/scraper/domUtils.js index c2729600..86617c41 100644 --- a/skyvern/webeye/scraper/domUtils.js +++ b/skyvern/webeye/scraper/domUtils.js @@ -1952,13 +1952,23 @@ function removeBoundingBoxes() { } } +function safeWindowScroll(x, y) { + if (typeof window.scroll === "function") { + window.scroll(x, y, { behavior: "instant" }); + } else if (typeof window.scrollTo === "function") { + window.scrollTo(x, y, { behavior: "instant" }); + } else { + console.error("window.scroll and window.scrollTo are both not supported"); + } +} + async function scrollToTop( draw_boxes, frame = "main.frame", frame_index = undefined, ) { removeBoundingBoxes(); - window.scroll({ left: 0, top: 0, behavior: "instant" }); + safeWindowScroll(0, 0); if (draw_boxes) { await buildElementsAndDrawBoundingBoxes(frame, frame_index); } @@ -1970,7 +1980,7 @@ function getScrollXY() { } function scrollToXY(x, y) { - window.scroll({ left: x, top: y, behavior: "instant" }); + safeWindowScroll(x, y); } async function scrollToNextPage(