@browserless/screenshot 13.10.1 → 13.11.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/package.json +2 -2
- package/src/index.js +13 -3
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.11.2",
|
|
6
6
|
"main": "src/index.js",
|
|
7
7
|
"author": {
|
|
8
8
|
"email": "hello@microlink.io",
|
|
@@ -70,5 +70,5 @@
|
|
|
70
70
|
"timeout": "2m",
|
|
71
71
|
"workerThreads": false
|
|
72
72
|
},
|
|
73
|
-
"gitHead": "
|
|
73
|
+
"gitHead": "e2deda7c4f16f6d926d9f4d61b6a523ffaba9ba7"
|
|
74
74
|
}
|
package/src/index.js
CHANGED
|
@@ -116,6 +116,13 @@ const isLossy = ({ type, path }) =>
|
|
|
116
116
|
? LOSSY_TYPES.has(type)
|
|
117
117
|
: LOSSY_EXTENSIONS.has(extname(path ?? '').toLowerCase())
|
|
118
118
|
|
|
119
|
+
// Captures stay binary until returned: the blank-page check and the overlay
|
|
120
|
+
// decode them with sharp, which reads a base64 string as raw bytes.
|
|
121
|
+
const encodeScreenshot = (image, encoding) =>
|
|
122
|
+
encoding === 'base64' && ArrayBuffer.isView(image)
|
|
123
|
+
? Buffer.from(image.buffer, image.byteOffset, image.byteLength).toString('base64')
|
|
124
|
+
: image
|
|
125
|
+
|
|
119
126
|
module.exports = ({ goto, ...gotoOpts }) => {
|
|
120
127
|
goto = goto || createGoto(gotoOpts)
|
|
121
128
|
|
|
@@ -127,6 +134,7 @@ module.exports = ({ goto, ...gotoOpts }) => {
|
|
|
127
134
|
overlay: overlayOpts = SCREENSHOT_DEFAULT_OPTS.overlay,
|
|
128
135
|
waitUntil = SCREENSHOT_DEFAULT_OPTS.waitUntil,
|
|
129
136
|
isPageReady = SCREENSHOT_DEFAULT_OPTS.isPageReady,
|
|
137
|
+
encoding,
|
|
130
138
|
...opts
|
|
131
139
|
} = {}
|
|
132
140
|
) => {
|
|
@@ -287,9 +295,11 @@ module.exports = ({ goto, ...gotoOpts }) => {
|
|
|
287
295
|
}
|
|
288
296
|
}
|
|
289
297
|
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
298
|
+
const image =
|
|
299
|
+
Object.keys(overlayOpts).length === 0
|
|
300
|
+
? screenshot
|
|
301
|
+
: await overlay(screenshot, { ...opts, ...overlayOpts, viewport: page.viewport() })
|
|
302
|
+
return encodeScreenshot(image, encoding)
|
|
293
303
|
} finally {
|
|
294
304
|
page.off('dialog', onDialog)
|
|
295
305
|
}
|