@browserless/screenshot 13.6.10 → 13.6.11
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 +11 -0
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.11",
|
|
6
6
|
"main": "src/index.js",
|
|
7
7
|
"author": {
|
|
8
8
|
"email": "hello@microlink.io",
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"svg-gradient": "~1.0.4"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
|
-
"@browserless/test": "13.6.
|
|
55
|
+
"@browserless/test": "13.6.11",
|
|
56
56
|
"ava": "5"
|
|
57
57
|
},
|
|
58
58
|
"engines": {
|
|
@@ -71,5 +71,5 @@
|
|
|
71
71
|
"timeout": "2m",
|
|
72
72
|
"workerThreads": false
|
|
73
73
|
},
|
|
74
|
-
"gitHead": "
|
|
74
|
+
"gitHead": "a1336c7b1837cd9fa0918a859f441ff5f74c1920"
|
|
75
75
|
}
|
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
|
|