@d-zero/puppeteer-scroll 3.1.14 → 3.1.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/dist/scroll-all-over.d.ts +5 -0
- package/dist/scroll-all-over.js +27 -0
- package/package.json +4 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 D-ZERO Co., Ltd.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -7,6 +7,11 @@ export type Options = {
|
|
|
7
7
|
};
|
|
8
8
|
/**
|
|
9
9
|
* Scrolls the page vertically until the end or a maximum height is reached.
|
|
10
|
+
*
|
|
11
|
+
* Detects stuck scrolling (e.g. fullpage.js or other scroll-jacking libraries
|
|
12
|
+
* that block `scrollBy` while `body.scrollHeight` exceeds the viewport) and
|
|
13
|
+
* bails out after {@link MAX_STUCK_ITERATIONS} consecutive iterations without
|
|
14
|
+
* progress.
|
|
10
15
|
* @param page - The Puppeteer page object.
|
|
11
16
|
* @param options - Optional parameters for scrolling.
|
|
12
17
|
* @param options.distance - The distance to scroll on each iteration (default: 100).
|
package/dist/scroll-all-over.js
CHANGED
|
@@ -1,6 +1,20 @@
|
|
|
1
1
|
import { delay } from '@d-zero/shared/delay';
|
|
2
|
+
/**
|
|
3
|
+
* Number of consecutive iterations without scroll progress before bailing out.
|
|
4
|
+
*
|
|
5
|
+
* Scroll-jacking libraries (e.g. fullpage.js) can block `scrollBy` while
|
|
6
|
+
* `body.scrollHeight` remains larger than the viewport, causing an infinite
|
|
7
|
+
* loop. Three stuck iterations (≈ 900 ms at the default interval) is enough
|
|
8
|
+
* to confirm that scrolling is genuinely blocked.
|
|
9
|
+
*/
|
|
10
|
+
const MAX_STUCK_ITERATIONS = 3;
|
|
2
11
|
/**
|
|
3
12
|
* Scrolls the page vertically until the end or a maximum height is reached.
|
|
13
|
+
*
|
|
14
|
+
* Detects stuck scrolling (e.g. fullpage.js or other scroll-jacking libraries
|
|
15
|
+
* that block `scrollBy` while `body.scrollHeight` exceeds the viewport) and
|
|
16
|
+
* bails out after {@link MAX_STUCK_ITERATIONS} consecutive iterations without
|
|
17
|
+
* progress.
|
|
4
18
|
* @param page - The Puppeteer page object.
|
|
5
19
|
* @param options - Optional parameters for scrolling.
|
|
6
20
|
* @param options.distance - The distance to scroll on each iteration (default: 100).
|
|
@@ -11,6 +25,8 @@ export async function scrollAllOver(page, options) {
|
|
|
11
25
|
const interval = options?.interval ?? 300;
|
|
12
26
|
let currentScrollY = 0;
|
|
13
27
|
let scrollHeight = await page.evaluate(() => document.body.scrollHeight);
|
|
28
|
+
let prevScrollY = -1;
|
|
29
|
+
let stuckCount = 0;
|
|
14
30
|
while (Math.ceil(currentScrollY) < Math.ceil(scrollHeight)) {
|
|
15
31
|
[currentScrollY, scrollHeight] = await page.evaluate(() => {
|
|
16
32
|
// Move the scroll position to the bottom of the page.
|
|
@@ -22,6 +38,17 @@ export async function scrollAllOver(page, options) {
|
|
|
22
38
|
];
|
|
23
39
|
});
|
|
24
40
|
options?.logger?.(currentScrollY, scrollHeight, 'Scrolling');
|
|
41
|
+
if (currentScrollY === prevScrollY) {
|
|
42
|
+
stuckCount++;
|
|
43
|
+
if (stuckCount >= MAX_STUCK_ITERATIONS) {
|
|
44
|
+
options?.logger?.(currentScrollY, scrollHeight, 'Scroll stuck, bailing out');
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
stuckCount = 0;
|
|
50
|
+
}
|
|
51
|
+
prevScrollY = currentScrollY;
|
|
25
52
|
await delay(interval);
|
|
26
53
|
}
|
|
27
54
|
options?.logger?.(currentScrollY, scrollHeight, 'End of page');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@d-zero/puppeteer-scroll",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.16",
|
|
4
4
|
"description": "Scroll function for puppeteer",
|
|
5
5
|
"author": "D-ZERO",
|
|
6
6
|
"license": "MIT",
|
|
@@ -23,12 +23,13 @@
|
|
|
23
23
|
"clean": "tsc --build --clean"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@d-zero/shared": "0.21.
|
|
26
|
+
"@d-zero/shared": "0.21.1"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"puppeteer": "24.37.5"
|
|
30
30
|
},
|
|
31
31
|
"peerDependencies": {
|
|
32
32
|
"puppeteer": "24.37.5"
|
|
33
|
-
}
|
|
33
|
+
},
|
|
34
|
+
"gitHead": "a347e4e88968fca7f2ace7639090d32014479d9f"
|
|
34
35
|
}
|