@browserless/screenshot 13.6.10 → 13.6.12
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 -4
- package/src/index.js +17 -6
- package/src/prepare-full-document.js +1 -1
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.6.
|
|
5
|
+
"version": "13.6.12",
|
|
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.6.
|
|
36
|
+
"@browserless/goto": "13.6.12",
|
|
37
37
|
"@kikobeats/content-type": "~1.0.4",
|
|
38
38
|
"@kikobeats/time-span": "~1.0.12",
|
|
39
39
|
"automad-prism-themes": "~0.3.7",
|
|
@@ -52,7 +52,6 @@
|
|
|
52
52
|
"svg-gradient": "~1.0.4"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
|
-
"@browserless/test": "13.6.10",
|
|
56
55
|
"ava": "5"
|
|
57
56
|
},
|
|
58
57
|
"engines": {
|
|
@@ -71,5 +70,5 @@
|
|
|
71
70
|
"timeout": "2m",
|
|
72
71
|
"workerThreads": false
|
|
73
72
|
},
|
|
74
|
-
"gitHead": "
|
|
73
|
+
"gitHead": "363898247585b3b6cd51781fbd55ca61ee9ef8a6"
|
|
75
74
|
}
|
package/src/index.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
const debug = require('debug-logfmt')('browserless:screenshot')
|
|
4
4
|
const { isContextDestroyed } = require('@browserless/errors')
|
|
5
5
|
const createGoto = require('@browserless/goto')
|
|
6
|
+
const { extname } = require('node:path')
|
|
6
7
|
const pReflect = require('p-reflect')
|
|
7
8
|
|
|
8
9
|
const isWhiteScreenshot = require('./is-white-screenshot')
|
|
@@ -96,6 +97,14 @@ const SCREENSHOT_DEFAULT_OPTS = {
|
|
|
96
97
|
isPageReady: defaultIsPageReady
|
|
97
98
|
}
|
|
98
99
|
|
|
100
|
+
const LOSSY_TYPES = new Set(['jpeg', 'webp'])
|
|
101
|
+
const LOSSY_EXTENSIONS = new Set(['.jpg', '.jpeg', '.webp'])
|
|
102
|
+
|
|
103
|
+
const isLossy = ({ type, path }) =>
|
|
104
|
+
type !== undefined
|
|
105
|
+
? LOSSY_TYPES.has(type)
|
|
106
|
+
: LOSSY_EXTENSIONS.has(extname(path ?? '').toLowerCase())
|
|
107
|
+
|
|
99
108
|
module.exports = ({ goto, ...gotoOpts }) => {
|
|
100
109
|
goto = goto || createGoto(gotoOpts)
|
|
101
110
|
|
|
@@ -110,6 +119,8 @@ module.exports = ({ goto, ...gotoOpts }) => {
|
|
|
110
119
|
...opts
|
|
111
120
|
} = {}
|
|
112
121
|
) => {
|
|
122
|
+
if (opts.quality !== undefined && !isLossy(opts)) opts.quality = undefined
|
|
123
|
+
|
|
113
124
|
let screenshot
|
|
114
125
|
let response
|
|
115
126
|
|
|
@@ -177,11 +188,11 @@ module.exports = ({ goto, ...gotoOpts }) => {
|
|
|
177
188
|
|
|
178
189
|
do {
|
|
179
190
|
screenshot = await captureWithNavigationRetry(
|
|
180
|
-
() =>
|
|
181
|
-
page.screenshot(
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
191
|
+
() => {
|
|
192
|
+
if (!opts.fullPage) return page.screenshot(opts)
|
|
193
|
+
const { fullPage, path, quality, ...probeOpts } = opts
|
|
194
|
+
return page.screenshot({ ...probeOpts, fullPage: false })
|
|
195
|
+
},
|
|
185
196
|
{ page, goto, timeout }
|
|
186
197
|
)
|
|
187
198
|
isWhite = await isWhiteScreenshot(screenshot)
|
|
@@ -195,7 +206,7 @@ module.exports = ({ goto, ...gotoOpts }) => {
|
|
|
195
206
|
if (isReady || elapsed() >= timeout) break
|
|
196
207
|
|
|
197
208
|
const remaining = timeout - elapsed()
|
|
198
|
-
if (opts.fullPage && !didHydrateAttempt
|
|
209
|
+
if (opts.fullPage && !didHydrateAttempt) {
|
|
199
210
|
didHydrateAttempt = true
|
|
200
211
|
const { hydrated, info } = await tryHydrateScroll(page, remaining)
|
|
201
212
|
didHydrateScroll = hydrated
|
|
@@ -222,7 +222,7 @@ const prepareFullDocument = async (page, { goto, timeout, scrolled = false } = {
|
|
|
222
222
|
duration: elapsed()
|
|
223
223
|
})
|
|
224
224
|
|
|
225
|
-
await scrollFullPageToLoadContent(page, scrollTimeout)
|
|
225
|
+
await pReflect(scrollFullPageToLoadContent(page, scrollTimeout))
|
|
226
226
|
debug('prepareFullDocument:scroll', { duration: elapsed() })
|
|
227
227
|
} else {
|
|
228
228
|
debug('prepareFullDocument:skipScroll', { duration: elapsed() })
|