Skip to content

Commit

Permalink
[plugin-web-app] Optimize wait for scroll completion (#4845)
Browse files Browse the repository at this point in the history
  • Loading branch information
valfirst authored Feb 22, 2024
1 parent 47bca34 commit bacb036
Showing 1 changed file with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,18 @@ try {
elementToScroll = currentWindow.frameElement;
currentWindow = currentWindow.parent;
}
currentWindow.addEventListener('scroll', clearTimeoutAndWait, false);

const safariBrowser = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
if (safariBrowser)
{
currentWindow.addEventListener('scroll', clearTimeoutAndWait, false);
}
else
{
// https://developer.mozilla.org/en-US/docs/Web/API/Document/scrollend_event
currentWindow.addEventListener("scrollend", scrollEndEventListener);
}

currentWindow.scrollBy(0, elementToScroll.getBoundingClientRect().top - currentWindow.innerHeight * stickyHeaderSize);
}
catch(e) {
Expand All @@ -35,6 +46,11 @@ function clearTimeoutAndWait(event) {
wait();
}

function scrollEndEventListener(event) {
currentWindow.removeEventListener("scrollend", scrollEndEventListener);
exit(true);
}

function isElementInsideOverflowContainer(element) {
let container = element.parentElement;
while (container) {
Expand Down

0 comments on commit bacb036

Please # to comment.