@d-zero/puppeteer-page-scan 4.1.0 → 4.2.1
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/dist/before-page-scan.js
CHANGED
|
@@ -10,6 +10,7 @@ export async function beforePageScan(page, url, options) {
|
|
|
10
10
|
const name = options?.name ?? 'default';
|
|
11
11
|
const width = options?.width ?? 1400;
|
|
12
12
|
const resolution = options?.resolution;
|
|
13
|
+
const timeout = options?.timeout;
|
|
13
14
|
listener?.('setViewport', { name, width, resolution });
|
|
14
15
|
await page.setViewport({
|
|
15
16
|
width,
|
|
@@ -20,11 +21,11 @@ export async function beforePageScan(page, url, options) {
|
|
|
20
21
|
});
|
|
21
22
|
if (page.url() === url) {
|
|
22
23
|
listener?.('load', { name, type: 'reaload' });
|
|
23
|
-
await page
|
|
24
|
+
await navigateWithFallback(page, url, timeout, true, listener, name);
|
|
24
25
|
}
|
|
25
26
|
else {
|
|
26
27
|
listener?.('load', { name, type: 'open' });
|
|
27
|
-
await page
|
|
28
|
+
await navigateWithFallback(page, url, timeout, false, listener, name);
|
|
28
29
|
}
|
|
29
30
|
for (const hook of options?.hooks ?? []) {
|
|
30
31
|
await hook(page, {
|
|
@@ -44,3 +45,43 @@ export async function beforePageScan(page, url, options) {
|
|
|
44
45
|
logger: (scrollY, scrollHeight, message) => listener?.('scroll', { name, scrollY, scrollHeight, message }),
|
|
45
46
|
});
|
|
46
47
|
}
|
|
48
|
+
/**
|
|
49
|
+
* Navigate with fallback from networkidle0 to networkidle2 on timeout
|
|
50
|
+
* @param page
|
|
51
|
+
* @param url
|
|
52
|
+
* @param timeout
|
|
53
|
+
* @param isReload
|
|
54
|
+
* @param listener
|
|
55
|
+
* @param name
|
|
56
|
+
*/
|
|
57
|
+
async function navigateWithFallback(page, url, timeout, isReload, listener, name) {
|
|
58
|
+
try {
|
|
59
|
+
// First attempt: networkidle0 (stricter)
|
|
60
|
+
if (isReload) {
|
|
61
|
+
await page.reload({ waitUntil: 'networkidle0', timeout });
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
await page.goto(url, { waitUntil: 'networkidle0', timeout });
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
// Check if it's a timeout error
|
|
69
|
+
if (error instanceof Error && error.message.includes('timeout')) {
|
|
70
|
+
listener?.('hook', {
|
|
71
|
+
name,
|
|
72
|
+
message: `networkidle0 timeout, retrying with networkidle2...`,
|
|
73
|
+
});
|
|
74
|
+
// Retry with networkidle2 (more lenient)
|
|
75
|
+
if (isReload) {
|
|
76
|
+
await page.reload({ waitUntil: 'networkidle2', timeout });
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
await page.goto(url, { waitUntil: 'networkidle2', timeout });
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
// Re-throw non-timeout errors
|
|
84
|
+
throw error;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@d-zero/puppeteer-page-scan",
|
|
3
|
-
"version": "4.1
|
|
3
|
+
"version": "4.2.1",
|
|
4
4
|
"description": "Scanning page function for puppeteer",
|
|
5
5
|
"author": "D-ZERO",
|
|
6
6
|
"license": "MIT",
|
|
@@ -24,13 +24,13 @@
|
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"@d-zero/puppeteer-general-actions": "1.2.1",
|
|
27
|
-
"@d-zero/puppeteer-scroll": "3.0.
|
|
27
|
+
"@d-zero/puppeteer-scroll": "3.0.7"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"puppeteer": "24.
|
|
30
|
+
"puppeteer": "24.23.0"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
33
|
-
"puppeteer": "24.
|
|
33
|
+
"puppeteer": "24.23.0"
|
|
34
34
|
},
|
|
35
|
-
"gitHead": "
|
|
35
|
+
"gitHead": "85b9a1f15d2db8798cf24a6a3f035cee1db6ba3d"
|
|
36
36
|
}
|