@browserless/pdf 10.8.0-beta.9 → 10.8.0

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.
Files changed (3) hide show
  1. package/LICENSE.md +0 -0
  2. package/package.json +6 -7
  3. package/src/index.js +15 -10
package/LICENSE.md CHANGED
File without changes
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@browserless/pdf",
3
3
  "description": "Sensible good defaults for exporting a website as PDF",
4
4
  "homepage": "https://browserless.js.org/#/?id=pdfurl-options",
5
- "version": "10.8.0-beta.9",
5
+ "version": "10.8.0",
6
6
  "main": "src",
7
7
  "repository": {
8
8
  "directory": "packages/pdf",
@@ -24,8 +24,8 @@
24
24
  "screen"
25
25
  ],
26
26
  "dependencies": {
27
- "@browserless/goto": "^10.8.0-beta.4",
28
- "@browserless/screenshot": "^10.8.0-beta.8",
27
+ "@browserless/goto": "^10.8.0",
28
+ "@browserless/screenshot": "^10.8.0",
29
29
  "@kikobeats/time-span": "~1.0.8",
30
30
  "debug-logfmt": "~1.4.0",
31
31
  "pretty-ms": "~7.0.1"
@@ -36,10 +36,9 @@
36
36
  "files": [
37
37
  "src"
38
38
  ],
39
+ "license": "MIT",
39
40
  "scripts": {
40
41
  "coverage": "exit 0",
41
42
  "test": "exit 0"
42
- },
43
- "license": "MIT",
44
- "gitHead": "2f08bb034d09fe09159427ea139f6487e31a4c40"
45
- }
43
+ }
44
+ }
package/src/index.js CHANGED
@@ -3,7 +3,6 @@
3
3
  const timeSpan = require('@kikobeats/time-span')({ format: n => Math.round(n) })
4
4
  const { isWhiteScreenshot } = require('@browserless/screenshot')
5
5
  const debug = require('debug-logfmt')('browserless:pdf')
6
- const { setTimeout } = require('node:timers/promises')
7
6
  const createGoto = require('@browserless/goto')
8
7
 
9
8
  const getMargin = unit => {
@@ -41,7 +40,7 @@ module.exports = ({ goto, ...gotoOpts } = {}) => {
41
40
  } else {
42
41
  await goto(page, { ...opts, url, waitUntil, waitUntilAuto })
43
42
  async function waitUntilAuto (page) {
44
- const timeout = goto.timeouts.action(goto.timeouts.base(opts.timeout))
43
+ const timeout = goto.timeouts.action(opts.timeout)
45
44
  let isWhite = false
46
45
  let retry = -1
47
46
 
@@ -50,16 +49,22 @@ module.exports = ({ goto, ...gotoOpts } = {}) => {
50
49
  do {
51
50
  ++retry
52
51
  const screenshotTime = timeSpan()
53
- isWhite = await isWhiteScreenshot(await page.screenshot(opts))
54
- debug('screenshot', { waitUntil, isWhite, retry, timeout, duration: screenshotTime() })
55
- if (retry > 0) {
56
- if (retry === 1) await goto.waitUntilAuto(page, { timeout: opts.timeout })
57
- else await setTimeout(500)
58
- }
52
+ ;[isWhite, pdfBuffer] = await Promise.all([
53
+ isWhiteScreenshot(
54
+ await page.screenshot({
55
+ ...opts,
56
+ optimizeForSpeed: true,
57
+ type: 'jpeg',
58
+ quality: 30
59
+ })
60
+ ),
61
+ generatePdf(page),
62
+ retry === 1 ? goto.waitUntilAuto(page, { timeout: opts.timeout }) : Promise.resolve()
63
+ ])
64
+ debug('retry', { waitUntil, isWhite, retry, duration: screenshotTime() })
59
65
  } while (isWhite && timePdf() < timeout)
60
66
 
61
- pdfBuffer = await generatePdf(page)
62
- debug({ waitUntil, isWhite, retry, timeout, duration: require('pretty-ms')(timePdf()) })
67
+ debug({ waitUntil, isWhite, timeout, duration: require('pretty-ms')(timePdf()) })
63
68
  }
64
69
  }
65
70