@@ -30,7 +30,42 @@ def check_page(self, page_url: str) -> (list, bool):
3030 )
3131 raise Exception (f"Failed to load page: { page_url } " )
3232
33- page .evaluate ("window.scrollTo(0, document.body.scrollHeight)" )
33+ page .evaluate ("""
34+ async () => {
35+ const scrollToBottom = async () => {
36+ return new Promise((resolve) => {
37+ const startPosition = window.pageYOffset || document.documentElement.scrollTop;
38+ const targetPosition = document.body.scrollHeight;
39+ const distance = targetPosition - startPosition;
40+ const duration = Math.max(1000, distance * 0.5); // Minimum 1 second, scales with distance
41+ const startTime = performance.now();
42+
43+ const easeInOutQuad = (t) => {
44+ return t < 0.5 ? 2 * t * t : -1 + (4 - 2 * t) * t;
45+ };
46+
47+ const animateScroll = (currentTime) => {
48+ const elapsed = currentTime - startTime;
49+ const progress = Math.min(elapsed / duration, 1);
50+ const eased = easeInOutQuad(progress);
51+ const currentPosition = startPosition + (distance * eased);
52+
53+ window.scrollTo(0, currentPosition);
54+
55+ if (progress < 1) {
56+ requestAnimationFrame(animateScroll);
57+ } else {
58+ resolve();
59+ }
60+ };
61+
62+ requestAnimationFrame(animateScroll);
63+ });
64+ };
65+
66+ return await scrollToBottom();
67+ }
68+ """ )
3469 page .wait_for_timeout (1000 )
3570
3671 images = page .locator ("img" ).all ()
0 commit comments