@browserless/screenshot 13.8.3 → 13.9.2
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/README.md +3 -3
- package/package.json +3 -3
- package/src/index.js +10 -3
- package/src/is-transient-context-loss.js +17 -0
- package/src/prepare-full-document.js +8 -2
- package/src/wait-for-ready.js +2 -2
package/README.md
CHANGED
|
@@ -25,7 +25,7 @@ npm install @browserless/screenshot --save
|
|
|
25
25
|
|
|
26
26
|
This package provides **advanced screenshot capture** with smart defaults, browser frame overlays, gradient backgrounds, and automatic code syntax highlighting. It wraps Puppeteer's `page.screenshot()` with features optimized for production use.
|
|
27
27
|
|
|
28
|
-
### What
|
|
28
|
+
### What this package does
|
|
29
29
|
|
|
30
30
|
The `@browserless/screenshot` package allows you to:
|
|
31
31
|
|
|
@@ -323,7 +323,7 @@ const buffer = await browserless.screenshot('https://example.com', {
|
|
|
323
323
|
└── index.js → Tests
|
|
324
324
|
```
|
|
325
325
|
|
|
326
|
-
### How
|
|
326
|
+
### How it fits in the monorepo
|
|
327
327
|
|
|
328
328
|
This is a **core functionality package** for screenshot capture:
|
|
329
329
|
|
|
@@ -331,7 +331,7 @@ This is a **core functionality package** for screenshot capture:
|
|
|
331
331
|
| -------------------- | ---------------------------------------------- |
|
|
332
332
|
| `browserless` (core) | Provides the `.screenshot()` method |
|
|
333
333
|
| `@browserless/cli` | Powers the `browserless screenshot` command |
|
|
334
|
-
| `@browserless/pdf` | Uses `
|
|
334
|
+
| `@browserless/pdf` | Uses `waitForReady` and `isWhiteScreenshot` |
|
|
335
335
|
|
|
336
336
|
### Dependencies
|
|
337
337
|
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@browserless/screenshot",
|
|
3
3
|
"description": "Capture high-quality screenshots of websites with overlay support, device emulation, and automated image optimization.",
|
|
4
4
|
"homepage": "https://browserless.js.org/#/?id=screenshoturl-options",
|
|
5
|
-
"version": "13.
|
|
5
|
+
"version": "13.9.2",
|
|
6
6
|
"main": "src/index.js",
|
|
7
7
|
"author": {
|
|
8
8
|
"email": "hello@microlink.io",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
],
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"@browserless/errors": "13.6.10",
|
|
36
|
-
"@browserless/goto": "13.
|
|
36
|
+
"@browserless/goto": "13.9.0",
|
|
37
37
|
"@kikobeats/content-type": "~1.0.4",
|
|
38
38
|
"@kikobeats/time-span": "~1.0.12",
|
|
39
39
|
"automad-prism-themes": "~0.3.7",
|
|
@@ -70,5 +70,5 @@
|
|
|
70
70
|
"timeout": "2m",
|
|
71
71
|
"workerThreads": false
|
|
72
72
|
},
|
|
73
|
-
"gitHead": "
|
|
73
|
+
"gitHead": "025ebb6f35fd65f3d92a36e1d5deaa7c080e404d"
|
|
74
74
|
}
|
package/src/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
const debug = require('debug-logfmt')('browserless:screenshot')
|
|
4
|
-
const { isContextDestroyed } = require('@browserless/errors')
|
|
5
4
|
const createGoto = require('@browserless/goto')
|
|
6
5
|
const { extname } = require('node:path')
|
|
7
6
|
const pReflect = require('p-reflect')
|
|
8
7
|
|
|
8
|
+
const isTransientContextLoss = require('./is-transient-context-loss')
|
|
9
9
|
const isWhiteScreenshot = require('./is-white-screenshot')
|
|
10
10
|
const waitForPrism = require('./pretty')
|
|
11
11
|
const prettyTimeSpan = require('./time-span')
|
|
@@ -22,15 +22,22 @@ const {
|
|
|
22
22
|
|
|
23
23
|
const timeSpan = require('@kikobeats/time-span')()
|
|
24
24
|
|
|
25
|
+
// No pacing here on purpose: `waitUntilAuto` is a network-idle wait, which on a
|
|
26
|
+
// live page costs at least its idle window (~500ms) and at most what is left of
|
|
27
|
+
// the budget. The runaway case was never a fast loop — it was retrying a page
|
|
28
|
+
// that was gone, where the wait returns instantly. Classify that and the loop
|
|
29
|
+
// paces itself on real work.
|
|
25
30
|
const captureWithNavigationRetry = async (capture, { page, goto, timeout }) => {
|
|
26
31
|
const elapsed = timeSpan()
|
|
32
|
+
const remaining = () => timeout - elapsed()
|
|
27
33
|
while (true) {
|
|
28
34
|
try {
|
|
29
35
|
return await capture()
|
|
30
36
|
} catch (error) {
|
|
31
|
-
if (!
|
|
37
|
+
if (!isTransientContextLoss(page, error) || remaining() <= 0) throw error
|
|
32
38
|
debug('captureWithNavigationRetry', { error: error.message })
|
|
33
|
-
await goto.waitUntilAuto(page, { timeout })
|
|
39
|
+
await goto.waitUntilAuto(page, { timeout: remaining() })
|
|
40
|
+
if (remaining() <= 0) throw error
|
|
34
41
|
}
|
|
35
42
|
}
|
|
36
43
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const { isContextDestroyed } = require('@browserless/errors')
|
|
4
|
+
|
|
5
|
+
// Tells a frame torn down mid-flight (a client-side navigation, which settles
|
|
6
|
+
// and retries fine) apart from a page we no longer have: once the page or its
|
|
7
|
+
// session is closed — the request ended and its context was destroyed — nothing
|
|
8
|
+
// it is waiting on can arrive, so waiting is spent on work nobody wants.
|
|
9
|
+
//
|
|
10
|
+
// `TargetCloseError` is puppeteer's own signal that the CDP session is detached
|
|
11
|
+
// (`CdpSession.send` raises it the moment `detached` is set). Ask it as well as
|
|
12
|
+
// the page: the session flips first, so between the two there is a window where
|
|
13
|
+
// every call throws yet `isClosed()` still answers false.
|
|
14
|
+
const isTransientContextLoss = (page, error) =>
|
|
15
|
+
isContextDestroyed(error) && error?.name !== 'TargetCloseError' && !page.isClosed()
|
|
16
|
+
|
|
17
|
+
module.exports = isTransientContextLoss
|
|
@@ -95,6 +95,11 @@ const settleDom = async (page, { idle, timeout }, label) => {
|
|
|
95
95
|
debug(label, { ...result, duration: Date.now() - started })
|
|
96
96
|
}
|
|
97
97
|
|
|
98
|
+
const isCompleteScroll = scroll =>
|
|
99
|
+
!!scroll?.hasOverflow &&
|
|
100
|
+
Number(scroll.pageHeight) > 0 &&
|
|
101
|
+
scroll.scrolledPx + (scroll.viewport || 0) >= scroll.pageHeight
|
|
102
|
+
|
|
98
103
|
const scrollFullPageToLoadContent = async (page, timeout) => {
|
|
99
104
|
const preQuiet = Math.min(PRE_QUIET_MS, Math.floor(timeout / 20))
|
|
100
105
|
const postQuiet = Math.min(POST_QUIET_MS, Math.floor(timeout / 20))
|
|
@@ -183,7 +188,7 @@ const scrollFullPageToLoadContent = async (page, timeout) => {
|
|
|
183
188
|
)
|
|
184
189
|
}
|
|
185
190
|
|
|
186
|
-
const hydrated =
|
|
191
|
+
const hydrated = isCompleteScroll(scroll)
|
|
187
192
|
return { ...scroll, hydrated, duration: Date.now() - started }
|
|
188
193
|
}
|
|
189
194
|
|
|
@@ -245,5 +250,6 @@ module.exports = {
|
|
|
245
250
|
scrollFullPageToLoadContent,
|
|
246
251
|
prepareFullDocument,
|
|
247
252
|
resolveScrollTimeout,
|
|
248
|
-
tryHydrateScroll
|
|
253
|
+
tryHydrateScroll,
|
|
254
|
+
isCompleteScroll
|
|
249
255
|
}
|
package/src/wait-for-ready.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
const { setTimeout: sleep } = require('node:timers/promises')
|
|
4
|
-
const
|
|
4
|
+
const isTransientContextLoss = require('./is-transient-context-loss')
|
|
5
5
|
|
|
6
6
|
const DEFAULT_QUIET_MS = 300
|
|
7
7
|
const DEFAULT_POLL_MS = 150
|
|
@@ -193,7 +193,7 @@ const waitForReady = async (
|
|
|
193
193
|
try {
|
|
194
194
|
signals = await page.evaluate(paintSignals)
|
|
195
195
|
} catch (error) {
|
|
196
|
-
if (!
|
|
196
|
+
if (!isTransientContextLoss(page, error)) throw error
|
|
197
197
|
resets++
|
|
198
198
|
lastHeight = -1
|
|
199
199
|
quietSince = 0
|