@browserless/pdf 10.8.0-beta.2 → 10.8.0-beta.4

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 (2) hide show
  1. package/package.json +4 -4
  2. package/src/index.js +11 -13
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.2",
5
+ "version": "10.8.0-beta.4",
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.7.13",
28
- "@browserless/screenshot": "^10.8.0-beta.0"
27
+ "@browserless/goto": "^10.8.0-beta.4",
28
+ "@browserless/screenshot": "^10.8.0-beta.4"
29
29
  },
30
30
  "engines": {
31
31
  "node": ">= 12"
@@ -38,5 +38,5 @@
38
38
  "test": "exit 0"
39
39
  },
40
40
  "license": "MIT",
41
- "gitHead": "7f293ddfa791439d087ce5ee3d87eca4d1abb08c"
41
+ "gitHead": "1661cb17734e79e9b9b0e35b5e0ea5cda7df4f08"
42
42
  }
package/src/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict'
2
2
 
3
- const { takeScreenshot } = require('@browserless/screenshot')
3
+ const { isWhiteScreenshot } = require('@browserless/screenshot')
4
4
  const debug = require('debug-logfmt')('browserless:pdf')
5
5
  const createGoto = require('@browserless/goto')
6
6
  const timeSpan = require('@kikobeats/time-span')({ format: require('pretty-ms') })
@@ -43,24 +43,22 @@ module.exports = ({ goto, ...gotoOpts } = {}) => {
43
43
  } else {
44
44
  await goto(page, { ...opts, url, waitUntil, waitUntilAuto })
45
45
  async function waitUntilAuto (page) {
46
+ const timeout = goto.timeouts.action(goto.timeouts.base(opts.timeout))
46
47
  let isWhite = false
47
- let retryCount = 0
48
- const maxRetries = 3
48
+ let retry = -1
49
49
 
50
50
  do {
51
- const screenshotResult = await takeScreenshot({ page, goto, opts })
52
- isWhite = screenshotResult.isWhite
53
-
54
- if (isWhite && retryCount < maxRetries) {
55
- retryCount++
56
- debug('screenshot:retry', { waitUntil, isWhite, retryCount, maxRetries })
57
- await setTimeout(500)
58
- await goto.waitUntilAuto(page, { timeout: opts.timeout })
51
+ const screenshotTime = timeSpan()
52
+ isWhite = await isWhiteScreenshot(await page.screenshot(opts))
53
+ debug('screenshot', { waitUntil, isWhite, retry, duration: screenshotTime() })
54
+ if (++retry > 0) {
55
+ if (retry === 1) await goto.waitUntilAuto(page, { timeout: opts.timeout })
56
+ else await setTimeout(100)
59
57
  }
60
- } while (isWhite && retryCount < maxRetries)
58
+ } while (isWhite && timePdf() < timeout)
61
59
 
62
60
  pdfBuffer = await generatePdf(page)
63
- debug('screenshot', { waitUntil, isWhite, retryCount, duration: timePdf() })
61
+ debug({ waitUntil, isWhite, retry, duration: timePdf() })
64
62
  }
65
63
  }
66
64