@browserless/pdf 13.6.12 → 13.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.
- package/package.json +4 -4
- package/src/index.js +25 -7
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.
|
|
5
|
+
"version": "13.8.0",
|
|
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.
|
|
34
|
-
"@browserless/screenshot": "13.
|
|
33
|
+
"@browserless/goto": "13.8.0",
|
|
34
|
+
"@browserless/screenshot": "13.8.0",
|
|
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": "
|
|
50
|
+
"gitHead": "c8ee02797b7f301426683171bf7132b0df695ca1"
|
|
51
51
|
}
|
package/src/index.js
CHANGED
|
@@ -73,19 +73,29 @@ module.exports = ({ goto, ...gotoOpts } = {}) => {
|
|
|
73
73
|
...rest
|
|
74
74
|
} = opts
|
|
75
75
|
|
|
76
|
+
const hasActionPdf =
|
|
77
|
+
Array.isArray(rest.actions) && rest.actions.some(action => action.type === 'pdf')
|
|
78
|
+
|
|
76
79
|
if (waitUntil !== 'auto') {
|
|
77
|
-
await goto(page, { ...rest, url, waitUntil })
|
|
78
|
-
|
|
79
|
-
|
|
80
|
+
const { actionCaptures } = await goto(page, { ...rest, url, waitUntil })
|
|
81
|
+
if (!hasActionPdf) {
|
|
82
|
+
await prepareFullDocument(page, { goto, timeout: rest.timeout })
|
|
83
|
+
}
|
|
84
|
+
return { actionCaptures, hasActionPdf }
|
|
80
85
|
}
|
|
81
86
|
|
|
82
87
|
let readiness
|
|
83
88
|
let isReady = false
|
|
84
89
|
let didHydrateScroll = false
|
|
85
90
|
|
|
86
|
-
await goto(page, {
|
|
91
|
+
const { actionCaptures } = await goto(page, {
|
|
92
|
+
...rest,
|
|
93
|
+
url,
|
|
94
|
+
waitUntil,
|
|
95
|
+
waitUntilAuto
|
|
96
|
+
})
|
|
87
97
|
|
|
88
|
-
if (isReady) {
|
|
98
|
+
if (isReady && !hasActionPdf) {
|
|
89
99
|
const prep = await prepareFullDocument(page, {
|
|
90
100
|
goto,
|
|
91
101
|
timeout: rest.timeout,
|
|
@@ -94,9 +104,10 @@ module.exports = ({ goto, ...gotoOpts } = {}) => {
|
|
|
94
104
|
readiness = { ...readiness, ...prep }
|
|
95
105
|
}
|
|
96
106
|
|
|
97
|
-
return readiness
|
|
107
|
+
return { readiness, actionCaptures, hasActionPdf }
|
|
98
108
|
|
|
99
109
|
async function waitUntilAuto (page, { response, timeout: autoTimeout } = {}) {
|
|
110
|
+
if (hasActionPdf) return
|
|
100
111
|
const timeout = autoTimeout ?? goto.timeouts.action(rest.timeout)
|
|
101
112
|
let didHydrateAttempt = false
|
|
102
113
|
|
|
@@ -165,7 +176,14 @@ module.exports = ({ goto, ...gotoOpts } = {}) => {
|
|
|
165
176
|
const pdf =
|
|
166
177
|
page =>
|
|
167
178
|
async (url, opts = {}) => {
|
|
168
|
-
await prepare(page, url, opts)
|
|
179
|
+
const prepared = await prepare(page, url, opts)
|
|
180
|
+
if (prepared?.hasActionPdf) {
|
|
181
|
+
const last = prepared.actionCaptures?.pdfs?.at(-1)
|
|
182
|
+
if (!last?.buffer) {
|
|
183
|
+
throw new Error('actions: pdf action produced no buffer')
|
|
184
|
+
}
|
|
185
|
+
return last.buffer
|
|
186
|
+
}
|
|
169
187
|
return render(page, opts)
|
|
170
188
|
}
|
|
171
189
|
|