From 49baf471ab7cba857c24b80c77273c54fdcb07fd Mon Sep 17 00:00:00 2001 From: LawyZheng Date: Fri, 10 May 2024 12:07:03 +0800 Subject: [PATCH] fix scrolling problem (#289) --- skyvern/webeye/scraper/domUtils.js | 39 +++++------------------------- 1 file changed, 6 insertions(+), 33 deletions(-) diff --git a/skyvern/webeye/scraper/domUtils.js b/skyvern/webeye/scraper/domUtils.js index 08ed0df7..6a332aec 100644 --- a/skyvern/webeye/scraper/domUtils.js +++ b/skyvern/webeye/scraper/domUtils.js @@ -1140,8 +1140,7 @@ function removeBoundingBoxes() { function scrollToTop(draw_boxes) { removeBoundingBoxes(); - window.scrollTo(0, 0); - scrollDownAndUp(); + window.scrollTo({ left: 0, top: 0, behavior: "instant" }); if (draw_boxes) { var elementsAndResultArray = buildTreeFromBody(); drawBoundingBoxes(elementsAndResultArray[0]); @@ -1153,40 +1152,14 @@ function scrollToNextPage(draw_boxes) { // remove bounding boxes, scroll to next page with 200px overlap, then draw bounding boxes again // return true if there is a next page, false otherwise removeBoundingBoxes(); - window.scrollBy(0, window.innerHeight - 200); - scrollUpAndDown(); + window.scrollBy({ + left: 0, + top: window.innerHeight - 200, + behavior: "instant", + }); if (draw_boxes) { var elementsAndResultArray = buildTreeFromBody(); drawBoundingBoxes(elementsAndResultArray[0]); } return window.scrollY; } - -function scrollUpAndDown() { - // remove select2-drop-above class to prevent dropdown from being rendered on top of the box - // then scroll up by 1 and scroll down by 1 - removeSelect2DropAbove(); - window.scrollBy(0, -1); - removeSelect2DropAbove(); - window.scrollBy(0, 1); -} - -function scrollDownAndUp() { - // remove select2-drop-above class to prevent dropdown from being rendered on top of the box - // then scroll up by 1 and scroll down by 1 - removeSelect2DropAbove(); - window.scrollBy(0, 1); - removeSelect2DropAbove(); - window.scrollBy(0, -1); -} - -function removeSelect2DropAbove() { - var select2DropAbove = document.getElementsByClassName("select2-drop-above"); - var allElements = []; - for (var i = 0; i < select2DropAbove.length; i++) { - allElements.push(select2DropAbove[i]); - } - allElements.forEach((ele) => { - ele.classList.remove("select2-drop-above"); - }); -}