@browserless/pdf 10.8.0-beta.1 → 10.8.0-beta.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.
Files changed (2) hide show
  1. package/package.json +3 -3
  2. package/src/index.js +11 -11
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.1",
5
+ "version": "10.8.0-beta.3",
6
6
  "main": "src",
7
7
  "repository": {
8
8
  "directory": "packages/pdf",
@@ -25,7 +25,7 @@
25
25
  ],
26
26
  "dependencies": {
27
27
  "@browserless/goto": "^10.7.13",
28
- "@browserless/screenshot": "^10.8.0-beta.0"
28
+ "@browserless/screenshot": "^10.8.0-beta.3"
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": "c94f407b23a2ad309f71069c1a3e4a9b74c09fd5"
41
+ "gitHead": "99ff22f6be1b8dfd3b5ebeeef36cc38ef583b6fb"
42
42
  }
package/src/index.js CHANGED
@@ -1,9 +1,10 @@
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') })
7
+ const { setTimeout } = require('node:timers/promises')
7
8
 
8
9
  const getMargin = unit => {
9
10
  if (!unit) return unit
@@ -42,23 +43,22 @@ module.exports = ({ goto, ...gotoOpts } = {}) => {
42
43
  } else {
43
44
  await goto(page, { ...opts, url, waitUntil, waitUntilAuto })
44
45
  async function waitUntilAuto (page) {
46
+ const timeout = goto.timeouts.action(goto.timeouts.base(opts.timeout))
45
47
  let isWhite = false
46
- let retryCount = 0
47
- const maxRetries = 3
48
+ let retry = -1
48
49
 
49
50
  do {
50
- const screenshotResult = await takeScreenshot({ page, goto, opts })
51
- isWhite = screenshotResult.isWhite
52
-
53
- if (isWhite && retryCount < maxRetries) {
54
- retryCount++
55
- debug('screenshot:retry', { waitUntil, isWhite, retryCount, maxRetries })
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
+ await setTimeout(100)
56
56
  await goto.waitUntilAuto(page, { timeout: opts.timeout })
57
57
  }
58
- } while (isWhite && retryCount < maxRetries)
58
+ } while (isWhite && timePdf() < timeout)
59
59
 
60
60
  pdfBuffer = await generatePdf(page)
61
- debug('screenshot', { waitUntil, isWhite, retryCount, duration: timePdf() })
61
+ debug({ waitUntil, isWhite, retry, duration: timePdf() })
62
62
  }
63
63
  }
64
64