@browserless/screenshot 9.3.0-beta.7 → 9.3.1
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 +9 -4
- package/src/pretty/index.js +7 -14
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@browserless/screenshot",
|
|
3
3
|
"description": "Take clean screenshot of any website",
|
|
4
4
|
"homepage": "https://browserless.js.org/#/?id=screenshoturl-options",
|
|
5
|
-
"version": "9.3.
|
|
5
|
+
"version": "9.3.1",
|
|
6
6
|
"main": "src/index.js",
|
|
7
7
|
"author": {
|
|
8
8
|
"email": "hello@microlink.io",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"screenshot"
|
|
29
29
|
],
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@browserless/goto": "^9.3.
|
|
31
|
+
"@browserless/goto": "^9.3.1",
|
|
32
32
|
"debug-logfmt": "~1.0.4",
|
|
33
33
|
"got": "~11.8.3",
|
|
34
34
|
"is-html-content": "~1.0.0",
|
|
@@ -58,5 +58,5 @@
|
|
|
58
58
|
"test": "exit 0"
|
|
59
59
|
},
|
|
60
60
|
"license": "MIT",
|
|
61
|
-
"gitHead": "
|
|
61
|
+
"gitHead": "898ac18eec3d0649c2f8d84211d469f9565a32e8"
|
|
62
62
|
}
|
package/src/index.js
CHANGED
|
@@ -55,10 +55,14 @@ module.exports = ({ goto, ...gotoOpts }) => {
|
|
|
55
55
|
let screenshot
|
|
56
56
|
let response
|
|
57
57
|
|
|
58
|
-
const beforeScreenshot = response =>
|
|
59
|
-
|
|
58
|
+
const beforeScreenshot = response => {
|
|
59
|
+
const timeout = goto.timeouts.action(goto.timeouts.base(opts.timeout))
|
|
60
|
+
return Promise.all(
|
|
60
61
|
[
|
|
61
|
-
{
|
|
62
|
+
{
|
|
63
|
+
fn: () => page.evaluate('document.fonts.ready'),
|
|
64
|
+
debug: 'beforeScreenshot:fontsReady'
|
|
65
|
+
},
|
|
62
66
|
{
|
|
63
67
|
fn: () => waitForPrism(page, response, { codeScheme, ...opts }),
|
|
64
68
|
debug: 'beforeScreenshot:waitForPrism'
|
|
@@ -67,8 +71,9 @@ module.exports = ({ goto, ...gotoOpts }) => {
|
|
|
67
71
|
fn: () => waitForImagesOnViewport(page),
|
|
68
72
|
debug: 'beforeScreenshot:waitForImagesOnViewport'
|
|
69
73
|
}
|
|
70
|
-
].map(({ fn, ...opts }) => goto.run({ fn: fn(),
|
|
74
|
+
].map(({ fn, ...opts }) => goto.run({ fn: fn(), ...opts, timeout }))
|
|
71
75
|
)
|
|
76
|
+
}
|
|
72
77
|
|
|
73
78
|
const takeScreenshot = async opts => {
|
|
74
79
|
screenshot = await page.screenshot(opts)
|
package/src/pretty/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
const debug = require('debug-logfmt')('browserless:screenshot')
|
|
4
|
+
const isHtmlContent = require('is-html-content')
|
|
4
5
|
const { readFile } = require('fs').promises
|
|
5
6
|
const { extension } = require('mime-types')
|
|
6
|
-
const isHtml = require('is-html-content')
|
|
7
7
|
const prettyMs = require('pretty-ms')
|
|
8
8
|
const timeSpan = require('time-span')
|
|
9
9
|
const path = require('path')
|
|
@@ -14,14 +14,14 @@ const getHtml = require('./html')
|
|
|
14
14
|
|
|
15
15
|
const PRETTY_CONTENT_TYPES = ['json', 'text', 'html']
|
|
16
16
|
|
|
17
|
-
const {
|
|
17
|
+
const { inject } = require('@browserless/goto')
|
|
18
18
|
|
|
19
19
|
const getContentType = headers => {
|
|
20
20
|
const contentType = extension(headers['content-type'])
|
|
21
21
|
return contentType === 'txt' ? 'text' : contentType
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
module.exports = async (page, response, { codeScheme, styles, scripts, modules }) => {
|
|
24
|
+
module.exports = async (page, response, { timeout, codeScheme, styles, scripts, modules }) => {
|
|
25
25
|
if (!response || !codeScheme) return
|
|
26
26
|
|
|
27
27
|
const contentType = getContentType(response.headers())
|
|
@@ -30,25 +30,18 @@ module.exports = async (page, response, { codeScheme, styles, scripts, modules }
|
|
|
30
30
|
|
|
31
31
|
const isHtmlContentType = contentType === 'html'
|
|
32
32
|
|
|
33
|
-
const [theme,
|
|
33
|
+
const [theme, content, prism] = await Promise.all([
|
|
34
34
|
getTheme(codeScheme),
|
|
35
35
|
response[isHtmlContentType ? 'text' : contentType](),
|
|
36
36
|
getPrism
|
|
37
37
|
])
|
|
38
38
|
|
|
39
|
-
if (isHtmlContentType &&
|
|
39
|
+
if (isHtmlContentType && isHtmlContent(content)) return
|
|
40
40
|
|
|
41
41
|
const timePretty = timeSpan()
|
|
42
|
-
const html = getHtml(
|
|
42
|
+
const html = getHtml(content, { contentType, prism, theme })
|
|
43
43
|
await page.setContent(html)
|
|
44
|
-
|
|
45
|
-
await Promise.all(
|
|
46
|
-
[
|
|
47
|
-
modules && injectScripts(page, modules, { type: 'modules' }),
|
|
48
|
-
scripts && injectScripts(page, scripts),
|
|
49
|
-
styles && injectStyles(page, styles)
|
|
50
|
-
].filter(Boolean)
|
|
51
|
-
)
|
|
44
|
+
await inject(page, { timeout, modules, scripts, styles })
|
|
52
45
|
|
|
53
46
|
debug('pretty', { duration: prettyMs(timePretty()) })
|
|
54
47
|
}
|