@browserless/screenshot 9.3.0-beta.9 → 9.3.3

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.3.0-beta.9",
5
+ "version": "9.3.3",
6
6
  "main": "src/index.js",
7
7
  "author": {
8
8
  "email": "hello@microlink.io",
@@ -28,11 +28,11 @@
28
28
  "screenshot"
29
29
  ],
30
30
  "dependencies": {
31
- "@browserless/goto": "^9.3.0-beta.9",
31
+ "@browserless/goto": "^9.3.3",
32
32
  "debug-logfmt": "~1.0.4",
33
33
  "got": "~11.8.3",
34
34
  "is-html-content": "~1.0.0",
35
- "is-url-http": "~2.2.5",
35
+ "is-url-http": "~2.2.7",
36
36
  "jimp": "~0.16.1",
37
37
  "map-values-deep": "~1.0.2",
38
38
  "mime-types": "~2.1.34",
@@ -43,9 +43,6 @@
43
43
  "svg-gradient": "~1.0.3",
44
44
  "time-span": "~4.0.0"
45
45
  },
46
- "devDependencies": {
47
- "express": "~4.17.1"
48
- },
49
46
  "engines": {
50
47
  "node": ">= 12"
51
48
  },
@@ -58,5 +55,5 @@
58
55
  "test": "exit 0"
59
56
  },
60
57
  "license": "MIT",
61
- "gitHead": "5917cbb975fba39b208fe7820d16a5655fa75420"
58
+ "gitHead": "e15c8a9fea38ad134170d52c9b8058010a3c7cd1"
62
59
  }
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
- Promise.all(
58
+ const beforeScreenshot = response => {
59
+ const timeout = goto.timeouts.action(goto.timeouts.base(opts.timeout))
60
+ return Promise.all(
60
61
  [
61
- { fn: () => page.evaluate('document.fonts.ready'), debug: 'beforeScreenshot:fontsReady' },
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(), timeout: goto.actionTimeout, ...opts }))
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)
@@ -35,7 +35,7 @@ const resetCSS = `<style>
35
35
  }
36
36
  </style>`
37
37
 
38
- const JSON_MAX_LENGTH = 76 * 0.5
38
+ const JSON_MAX_LENGTH = 72 * 0.5
39
39
  const TEXT_MAX_LENGTH = 96 * 0.6
40
40
 
41
41
  const truncate = (input, maxLength) => {
@@ -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 { injectScripts, injectStyles } = require('@browserless/goto')
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, payload, prism] = await Promise.all([
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 && isHtml(payload)) return
39
+ if (isHtmlContentType && isHtmlContent(content)) return
40
40
 
41
41
  const timePretty = timeSpan()
42
- const html = getHtml(payload, { contentType, prism, theme })
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
  }
@@ -1,4 +1,4 @@
1
- /* PrismJS 1.25.0
1
+ /* PrismJS 1.26.0
2
2
  https://prismjs.com/download.html#themes=prism&languages=clike+javascript */
3
3
  var _self =
4
4
  'undefined' != typeof window
@@ -7,7 +7,7 @@ var _self =
7
7
  ? self
8
8
  : {},
9
9
  Prism = (function (u) {
10
- var c = /\blang(?:uage)?-([\w-]+)\b/i,
10
+ var t = /(?:^|\s)lang(?:uage)?-([\w-]+)(?=\s|$)/i,
11
11
  n = 0,
12
12
  e = {},
13
13
  M = {
@@ -54,8 +54,16 @@ var _self =
54
54
  }
55
55
  },
56
56
  getLanguage: function (e) {
57
- for (; e && !c.test(e.className); ) e = e.parentElement
58
- return e ? (e.className.match(c) || [, 'none'])[1].toLowerCase() : 'none'
57
+ for (; e; ) {
58
+ var n = t.exec(e.className)
59
+ if (n) return n[1].toLowerCase()
60
+ e = e.parentElement
61
+ }
62
+ return 'none'
63
+ },
64
+ setLanguage: function (e, n) {
65
+ ;(e.className = e.className.replace(RegExp(t, 'gi'), '')),
66
+ e.classList.add('language-' + n)
59
67
  },
60
68
  currentScript: function () {
61
69
  if ('undefined' == typeof document) return null
@@ -141,11 +149,9 @@ var _self =
141
149
  highlightElement: function (e, n, t) {
142
150
  var r = M.util.getLanguage(e),
143
151
  a = M.languages[r]
144
- e.className = e.className.replace(c, '').replace(/\s+/g, ' ') + ' language-' + r
152
+ M.util.setLanguage(e, r)
145
153
  var i = e.parentElement
146
- i &&
147
- 'pre' === i.nodeName.toLowerCase() &&
148
- (i.className = i.className.replace(c, '').replace(/\s+/g, ' ') + ' language-' + r)
154
+ i && 'pre' === i.nodeName.toLowerCase() && M.util.setLanguage(i, r)
149
155
  var l = { element: e, language: r, grammar: a, code: e.textContent }
150
156
  function o (e) {
151
157
  ;(l.highlightedCode = e),
@@ -207,23 +213,23 @@ var _self =
207
213
  h = !!c.greedy,
208
214
  d = c.alias
209
215
  if (h && !c.pattern.global) {
210
- var p = c.pattern.toString().match(/[imsuy]*$/)[0]
211
- c.pattern = RegExp(c.pattern.source, p + 'g')
216
+ var v = c.pattern.toString().match(/[imsuy]*$/)[0]
217
+ c.pattern = RegExp(c.pattern.source, v + 'g')
212
218
  }
213
219
  for (
214
- var v = c.pattern || c, m = a.next, y = i;
220
+ var p = c.pattern || c, m = a.next, y = i;
215
221
  m !== t.tail && !(l && y >= l.reach);
216
222
  y += m.value.length, m = m.next
217
223
  ) {
218
- var b = m.value
224
+ var k = m.value
219
225
  if (t.length > n.length) return
220
- if (!(b instanceof W)) {
221
- var k,
222
- x = 1
226
+ if (!(k instanceof W)) {
227
+ var x,
228
+ b = 1
223
229
  if (h) {
224
- if (!(k = z(v, y, n, f))) break
225
- var w = k.index,
226
- A = k.index + k[0].length,
230
+ if (!(x = z(p, y, n, f)) || x.index >= n.length) break
231
+ var w = x.index,
232
+ A = x.index + x[0].length,
227
233
  P = y
228
234
  for (P += m.value.length; P <= w; ) (m = m.next), (P += m.value.length)
229
235
  if (((P -= m.value.length), (y = P), m.value instanceof W)) continue
@@ -232,20 +238,20 @@ var _self =
232
238
  E !== t.tail && (P < A || 'string' == typeof E.value);
233
239
  E = E.next
234
240
  )
235
- x++, (P += E.value.length)
236
- x--, (b = n.slice(y, P)), (k.index -= y)
237
- } else if (!(k = z(v, 0, b, f))) continue
238
- var w = k.index,
239
- S = k[0],
240
- O = b.slice(0, w),
241
- L = b.slice(w + S.length),
242
- N = y + b.length
243
- l && N > l.reach && (l.reach = N)
244
- var j = m.prev
245
- O && ((j = I(t, j, O)), (y += O.length)), q(t, j, x)
246
- var C = new W(o, g ? M.tokenize(S, g) : S, d, S)
247
- if (((m = I(t, j, C)), L && I(t, m, L), 1 < x)) {
248
- var _ = { cause: o + ',' + u, reach: N }
241
+ b++, (P += E.value.length)
242
+ b--, (k = n.slice(y, P)), (x.index -= y)
243
+ } else if (!(x = z(p, 0, k, f))) continue
244
+ var w = x.index,
245
+ L = x[0],
246
+ S = k.slice(0, w),
247
+ O = k.slice(w + L.length),
248
+ j = y + k.length
249
+ l && j > l.reach && (l.reach = j)
250
+ var C = m.prev
251
+ S && ((C = I(t, C, S)), (y += S.length)), q(t, C, b)
252
+ var N = new W(o, g ? M.tokenize(L, g) : L, d, L)
253
+ if (((m = I(t, C, N)), O && I(t, m, O), 1 < b)) {
254
+ var _ = { cause: o + ',' + u, reach: j }
249
255
  e(n, t, r, m.prev, y, _), l && _.reach > l.reach && (l.reach = _.reach)
250
256
  }
251
257
  }
@@ -359,19 +365,19 @@ var _self =
359
365
  )),
360
366
  M
361
367
  )
362
- var t = M.util.currentScript()
363
- function r () {
368
+ var r = M.util.currentScript()
369
+ function a () {
364
370
  M.manual || M.highlightAll()
365
371
  }
366
372
  if (
367
- (t && ((M.filename = t.src), t.hasAttribute('data-manual') && (M.manual = !0)), !M.manual)
373
+ (r && ((M.filename = r.src), r.hasAttribute('data-manual') && (M.manual = !0)), !M.manual)
368
374
  ) {
369
- var a = document.readyState
370
- 'loading' === a || ('interactive' === a && t && t.defer)
371
- ? document.addEventListener('DOMContentLoaded', r)
375
+ var l = document.readyState
376
+ 'loading' === l || ('interactive' === l && r && r.defer)
377
+ ? document.addEventListener('DOMContentLoaded', a)
372
378
  : window.requestAnimationFrame
373
- ? window.requestAnimationFrame(r)
374
- : window.setTimeout(r, 16)
379
+ ? window.requestAnimationFrame(a)
380
+ : window.setTimeout(a, 16)
375
381
  }
376
382
  return M
377
383
  })(_self)
@@ -384,12 +390,12 @@ Prism.languages.clike = {
384
390
  ],
385
391
  string: { pattern: /(["'])(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/, greedy: !0 },
386
392
  'class-name': {
387
- pattern: /(\b(?:class|interface|extends|implements|trait|instanceof|new)\s+|\bcatch\s+\()[\w.\\]+/i,
393
+ pattern: /(\b(?:class|extends|implements|instanceof|interface|new|trait)\s+|\bcatch\s+\()[\w.\\]+/i,
388
394
  lookbehind: !0,
389
395
  inside: { punctuation: /[.\\]/ }
390
396
  },
391
- keyword: /\b(?:if|else|while|do|for|return|in|instanceof|function|new|try|throw|catch|finally|null|break|continue)\b/,
392
- boolean: /\b(?:true|false)\b/,
397
+ keyword: /\b(?:break|catch|continue|do|else|finally|for|function|if|in|instanceof|new|null|return|throw|try|while)\b/,
398
+ boolean: /\b(?:false|true)\b/,
393
399
  function: /\b\w+(?=\()/,
394
400
  number: /\b0x[\da-f]+\b|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:e[+-]?\d+)?/i,
395
401
  operator: /[<>]=?|[!=]=?=?|--?|\+\+?|&&?|\|\|?|[?*/~^%]/,
@@ -399,7 +405,7 @@ Prism.languages.clike = {
399
405
  'class-name': [
400
406
  Prism.languages.clike['class-name'],
401
407
  {
402
- pattern: /(^|[^$\w\xA0-\uFFFF])(?!\s)[_$A-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\.(?:prototype|constructor))/,
408
+ pattern: /(^|[^$\w\xA0-\uFFFF])(?!\s)[_$A-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\.(?:constructor|prototype))/,
403
409
  lookbehind: !0
404
410
  }
405
411
  ],
@@ -411,12 +417,17 @@ Prism.languages.clike = {
411
417
  }
412
418
  ],
413
419
  function: /#?(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*(?:\.\s*(?:apply|bind|call)\s*)?\()/,
414
- number: /\b(?:(?:0[xX](?:[\dA-Fa-f](?:_[\dA-Fa-f])?)+|0[bB](?:[01](?:_[01])?)+|0[oO](?:[0-7](?:_[0-7])?)+)n?|(?:\d(?:_\d)?)+n|NaN|Infinity)\b|(?:\b(?:\d(?:_\d)?)+\.?(?:\d(?:_\d)?)*|\B\.(?:\d(?:_\d)?)+)(?:[Ee][+-]?(?:\d(?:_\d)?)+)?/,
420
+ number: {
421
+ pattern: RegExp(
422
+ '(^|[^\\w$])(?:NaN|Infinity|0[bB][01]+(?:_[01]+)*n?|0[oO][0-7]+(?:_[0-7]+)*n?|0[xX][\\dA-Fa-f]+(?:_[\\dA-Fa-f]+)*n?|\\d+(?:_\\d+)*n|(?:\\d+(?:_\\d+)*(?:\\.(?:\\d+(?:_\\d+)*)?)?|\\.\\d+(?:_\\d+)*)(?:[Ee][+-]?\\d+(?:_\\d+)*)?)(?![\\w$])'
423
+ ),
424
+ lookbehind: !0
425
+ },
415
426
  operator: /--|\+\+|\*\*=?|=>|&&=?|\|\|=?|[!=]==|<<=?|>>>?=?|[-+*/%&|^!=<>]=?|\.{3}|\?\?=?|\?\.?|[~:]/
416
427
  })),
417
428
  (Prism.languages.javascript[
418
429
  'class-name'
419
- ][0].pattern = /(\b(?:class|interface|extends|implements|instanceof|new)\s+)[\w.\\]+/),
430
+ ][0].pattern = /(\b(?:class|extends|implements|instanceof|interface|new)\s+)[\w.\\]+/),
420
431
  Prism.languages.insertBefore('javascript', 'keyword', {
421
432
  regex: {
422
433
  pattern: /((?:^|[^$\w\xA0-\uFFFF."'\])\s]|\b(?:return|yield))\s*)\/(?:\[(?:[^\]\\\r\n]|\\.)*\]|\\.|[^/\\\[\r\n])+\/[dgimyus]{0,7}(?=(?:\s|\/\*(?:[^*]|\*(?!\/))*\*\/)*(?:$|[\r\n,.;:})\]]|\/\/))/,
@@ -478,6 +489,19 @@ Prism.languages.clike = {
478
489
  },
479
490
  string: /[\s\S]+/
480
491
  }
492
+ },
493
+ 'string-property': {
494
+ pattern: /((?:^|[,{])[ \t]*)(["'])(?:\\(?:\r\n|[\s\S])|(?!\2)[^\\\r\n])*\2(?=\s*:)/m,
495
+ lookbehind: !0,
496
+ greedy: !0,
497
+ alias: 'property'
498
+ }
499
+ }),
500
+ Prism.languages.insertBefore('javascript', 'operator', {
501
+ 'literal-property': {
502
+ pattern: /((?:^|[,{])[ \t]*)(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*:)/m,
503
+ lookbehind: !0,
504
+ alias: 'property'
481
505
  }
482
506
  }),
483
507
  Prism.languages.markup &&