@@ -24,6 +24,20 @@ async function createBrowser(opts) {
2424 return puppeteer . launch ( browserOpts ) ;
2525}
2626
27+ async function getFullPageHeight ( page ) {
28+ const height = await page . evaluate ( ( ) => {
29+ const { body, documentElement } = document ;
30+ return Math . max (
31+ body . scrollHeight ,
32+ body . offsetHeight ,
33+ documentElement . clientHeight ,
34+ documentElement . scrollHeight ,
35+ documentElement . offsetHeight
36+ ) ;
37+ } ) ;
38+ return height ;
39+ }
40+
2741async function render ( _opts = { } ) {
2842 const opts = _ . merge ( {
2943 cookies : [ ] ,
@@ -50,7 +64,7 @@ async function render(_opts = {}) {
5064 failEarly : false ,
5165 } , _opts ) ;
5266
53- if ( _ . get ( _opts , 'pdf.width' ) && _ . get ( _opts , 'pdf.height' ) ) {
67+ if ( ( _ . get ( _opts , 'pdf.width' ) && _ . get ( _opts , 'pdf.height' ) ) || _ . get ( opts , 'pdf.fullPage ') ) {
5468 // pdf.format always overrides width and height, so we must delete it
5569 // when user explicitly wants to set width and height
5670 opts . pdf . format = undefined ;
@@ -154,6 +168,10 @@ async function render(_opts = {}) {
154168 }
155169
156170 if ( opts . output === 'pdf' ) {
171+ if ( opts . pdf . fullPage ) {
172+ const height = await getFullPageHeight ( page ) ;
173+ opts . pdf . height = height ;
174+ }
157175 data = await page . pdf ( opts . pdf ) ;
158176 } else if ( opts . output === 'html' ) {
159177 data = await page . evaluate ( ( ) => document . body . innerHTML ) ;
0 commit comments