@browserless/pdf 13.1.5 → 13.1.7

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 +21 -12
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@browserless/pdf",
3
3
  "description": "Convert websites to high-quality PDFs with customizable margins, background printing, and optimized scaling.",
4
4
  "homepage": "https://browserless.js.org/#/?id=pdfurl-options",
5
- "version": "13.1.5",
5
+ "version": "13.1.7",
6
6
  "main": "src",
7
7
  "author": {
8
8
  "email": "hello@microlink.io",
@@ -30,8 +30,8 @@
30
30
  "website-to-pdf"
31
31
  ],
32
32
  "dependencies": {
33
- "@browserless/goto": "13.1.5",
34
- "@browserless/screenshot": "13.1.5",
33
+ "@browserless/goto": "13.1.7",
34
+ "@browserless/screenshot": "13.1.7",
35
35
  "@kikobeats/time-span": "~1.0.12",
36
36
  "debug-logfmt": "~1.4.10",
37
37
  "p-reflect": "~2.1.0",
@@ -47,5 +47,5 @@
47
47
  "test": "exit 0"
48
48
  },
49
49
  "license": "MIT",
50
- "gitHead": "9a7d700eced6febad30d2592b4296a5a49270d31"
50
+ "gitHead": "cb9a0c6fc11176da209ba9bc33bca5a47c3aabbe"
51
51
  }
package/src/index.js CHANGED
@@ -3,6 +3,7 @@
3
3
  const timeSpan = require('@kikobeats/time-span')({ format: n => Math.round(n) })
4
4
  const pReflect = require('p-reflect')
5
5
  const {
6
+ captureWithNavigationRetry,
6
7
  isWhiteScreenshot,
7
8
  waitForDomStability,
8
9
  resolveWaitForDom,
@@ -41,12 +42,16 @@ module.exports = ({ goto, ...gotoOpts } = {}) => {
41
42
  const waitForDomOpts = resolveWaitForDom(waitForDom)
42
43
 
43
44
  const generatePdf = page =>
44
- page.pdf({
45
- ...opts,
46
- margin: getMargin(margin),
47
- printBackground,
48
- scale
49
- })
45
+ captureWithNavigationRetry(
46
+ () =>
47
+ page.pdf({
48
+ ...opts,
49
+ margin: getMargin(margin),
50
+ printBackground,
51
+ scale
52
+ }),
53
+ { page, goto, timeout: goto.timeouts.action(opts.timeout) }
54
+ )
50
55
 
51
56
  const waitForDomStabilityResult = async page => {
52
57
  if (!waitForDomOpts) return
@@ -77,12 +82,16 @@ module.exports = ({ goto, ...gotoOpts } = {}) => {
77
82
  do {
78
83
  ++retry
79
84
  const screenshotTime = timeSpan()
80
- const screenshot = await page.screenshot({
81
- ...opts,
82
- optimizeForSpeed: true,
83
- type: 'jpeg',
84
- quality: 30
85
- })
85
+ const screenshot = await captureWithNavigationRetry(
86
+ () =>
87
+ page.screenshot({
88
+ ...opts,
89
+ optimizeForSpeed: true,
90
+ type: 'jpeg',
91
+ quality: 30
92
+ }),
93
+ { page, goto, timeout }
94
+ )
86
95
  isWhite = await isWhiteScreenshot(screenshot)
87
96
  if (isWhite) await goto.waitUntilAuto(page, { timeout: opts.timeout })
88
97
  debug('retry', { waitUntil, isWhite, retry, duration: screenshotTime() })