@browserless/screenshot 9.2.2 → 9.2.9

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 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.2.2",
5
+ "version": "9.2.9",
6
6
  "main": "src/index.js",
7
7
  "author": {
8
8
  "email": "hello@microlink.io",
@@ -28,20 +28,19 @@
28
28
  "screenshot"
29
29
  ],
30
30
  "dependencies": {
31
- "@browserless/goto": "^9.2.1",
32
- "cli-truncate": "~2.1.0",
31
+ "@browserless/goto": "^9.2.6",
33
32
  "debug-logfmt": "~1.0.4",
34
33
  "got": "~11.8.2",
35
34
  "is-html-content": "~1.0.0",
36
35
  "is-url-http": "~2.2.4",
37
36
  "jimp": "~0.16.1",
38
37
  "map-values-deep": "~1.0.2",
39
- "mime-types": "~2.1.31",
38
+ "mime-types": "~2.1.32",
40
39
  "p-reflect": "~2.1.0",
41
40
  "p-timeout": "~4.1.0",
42
41
  "pretty-ms": "~7.0.1",
43
42
  "prism-themes": "~1.9.0",
44
- "sharp": "~0.29.0",
43
+ "sharp": "~0.29.1",
45
44
  "svg-gradient": "~1.0.3",
46
45
  "time-span": "~4.0.0"
47
46
  },
@@ -60,5 +59,5 @@
60
59
  "test": "exit 0"
61
60
  },
62
61
  "license": "MIT",
63
- "gitHead": "30f2e6908531a1300cd5e35eda095fa07d33cb9b"
62
+ "gitHead": "966ae6a064a47367a92427b93acb891a9d27830b"
64
63
  }
package/src/index.js CHANGED
@@ -57,13 +57,14 @@ module.exports = ({ goto, ...gotoOpts }) => {
57
57
  ) => {
58
58
  let screenshot
59
59
  let response
60
+
60
61
  const beforeScreenshot = response =>
61
- pReflect(
62
- Promise.all([
63
- page.evaluate(() => document.fonts.ready),
62
+ Promise.all(
63
+ [
64
+ page.evaluate('document.fonts.ready'),
64
65
  waitForPrism(page, response, { codeScheme, ...opts }),
65
- pTimeout(waitForImagesOnViewport(page, { timeout }), timeout)
66
- ])
66
+ waitForImagesOnViewport(page)
67
+ ].map(fn => pReflect(pTimeout(fn, timeout)))
67
68
  )
68
69
 
69
70
  const takeScreenshot = async opts => {
@@ -3,7 +3,6 @@
3
3
  'use strict'
4
4
 
5
5
  const mapValuesDeep = require('map-values-deep')
6
- const truncate = require('cli-truncate')
7
6
 
8
7
  const resetCSS = `<style>
9
8
  * {
@@ -36,17 +35,23 @@ const resetCSS = `<style>
36
35
  }
37
36
  </style>`
38
37
 
39
- const JSON_MAX_LENGTH = 80 * 0.5
40
- const TEXT_MAX_LENGTH = 100 * 0.6
38
+ const JSON_MAX_LENGTH = 76 * 0.5
39
+ const TEXT_MAX_LENGTH = 96 * 0.6
40
+
41
+ const truncate = (input, maxLength) => {
42
+ let text = input.slice(0, maxLength)
43
+ if (text.length < input.length) text = text.trim() + '…'
44
+ return text
45
+ }
41
46
 
42
47
  const compactJSON = payload => {
43
48
  const sanetized = mapValuesDeep(payload, value => {
44
49
  if (typeof value !== 'string') return value
45
- return truncate(value, JSON_MAX_LENGTH, { position: 'end' }).trim()
50
+ return truncate(value, JSON_MAX_LENGTH)
46
51
  })
47
52
 
48
53
  return (
49
- JSON.stringify(sanetized, null, 2)
54
+ JSON.stringify(sanetized, null, 4)
50
55
  // compact objects '},\n {' → '}, {'
51
56
  .replace(new RegExp('},\\n {', 'g'), '}, {')
52
57
  // compact array object start '[,\n {' → '[{'
@@ -59,7 +64,7 @@ const compactJSON = payload => {
59
64
  const compactText = payload => {
60
65
  return payload
61
66
  .split('\n')
62
- .map(str => truncate(str, TEXT_MAX_LENGTH, { position: 'end' }).trim())
67
+ .map(str => truncate(str, TEXT_MAX_LENGTH))
63
68
  .join('\n')
64
69
  }
65
70