@browserless/screenshot 13.6.12 → 13.8.0
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/package.json +3 -3
- package/src/index.js +29 -10
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.8.0",
|
|
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.8.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": "c8ee02797b7f301426683171bf7132b0df695ca1"
|
|
74
74
|
}
|
package/src/index.js
CHANGED
|
@@ -241,22 +241,33 @@ module.exports = ({ goto, ...gotoOpts }) => {
|
|
|
241
241
|
|
|
242
242
|
try {
|
|
243
243
|
const timeScreenshot = prettyTimeSpan()
|
|
244
|
+
const hasActionScreenshot =
|
|
245
|
+
Array.isArray(opts.actions) && opts.actions.some(action => action.type === 'screenshot')
|
|
246
|
+
let actionCaptures
|
|
244
247
|
|
|
245
248
|
if (waitUntil !== 'auto') {
|
|
246
|
-
;({ response } = await goto(page, { ...opts, url, waitUntil }))
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
249
|
+
;({ response, actionCaptures } = await goto(page, { ...opts, url, waitUntil }))
|
|
250
|
+
if (!hasActionScreenshot) {
|
|
251
|
+
const screenshotOpts = await beforeScreenshot(page, response, opts)
|
|
252
|
+
if (opts.fullPage) {
|
|
253
|
+
await prepareFullDocument(page, { goto, timeout: opts.timeout })
|
|
254
|
+
}
|
|
255
|
+
screenshot = await captureExpanded(
|
|
256
|
+
opts.fullPage,
|
|
257
|
+
{ ...opts, ...screenshotOpts },
|
|
258
|
+
goto.timeouts.action(opts.timeout)
|
|
259
|
+
)
|
|
250
260
|
}
|
|
251
|
-
screenshot = await captureExpanded(
|
|
252
|
-
opts.fullPage,
|
|
253
|
-
{ ...opts, ...screenshotOpts },
|
|
254
|
-
goto.timeouts.action(opts.timeout)
|
|
255
|
-
)
|
|
256
261
|
debug('screenshot', { waitUntil, duration: timeScreenshot() })
|
|
257
262
|
} else {
|
|
258
|
-
;({ response } = await goto(page, {
|
|
263
|
+
;({ response, actionCaptures } = await goto(page, {
|
|
264
|
+
...opts,
|
|
265
|
+
url,
|
|
266
|
+
waitUntil,
|
|
267
|
+
waitUntilAuto
|
|
268
|
+
}))
|
|
259
269
|
async function waitUntilAuto (page, { response }) {
|
|
270
|
+
if (hasActionScreenshot) return
|
|
260
271
|
const screenshotOpts = await beforeScreenshot(page, response, opts)
|
|
261
272
|
const { isWhite, isReady, retry } = await takeScreenshot({
|
|
262
273
|
...opts,
|
|
@@ -274,6 +285,14 @@ module.exports = ({ goto, ...gotoOpts }) => {
|
|
|
274
285
|
}
|
|
275
286
|
}
|
|
276
287
|
|
|
288
|
+
if (hasActionScreenshot) {
|
|
289
|
+
const last = actionCaptures?.screenshots?.at(-1)
|
|
290
|
+
if (!last?.buffer) {
|
|
291
|
+
throw new Error('actions: screenshot action produced no buffer')
|
|
292
|
+
}
|
|
293
|
+
screenshot = last.buffer
|
|
294
|
+
}
|
|
295
|
+
|
|
277
296
|
return Object.keys(overlayOpts).length === 0
|
|
278
297
|
? screenshot
|
|
279
298
|
: overlay(screenshot, { ...opts, ...overlayOpts, viewport: page.viewport() })
|