File tree Expand file tree Collapse file tree 1 file changed +12
-3
lines changed Expand file tree Collapse file tree 1 file changed +12
-3
lines changed Original file line number Diff line number Diff line change @@ -75,11 +75,15 @@ export default class SaveUrl {
7575 timeout = 2000 ,
7676 height = 800 ,
7777 width = 400 ,
78+ mobile = true ,
79+ pdf = null ,
7880 killEvent = "kill"
7981 } = { } as any } = event ;
8082
8183 // const file = await TempFileService.getTempFile("a.png");
8284
85+ const asPdf = pdf ? JSON . parse ( pdf ) : null ;
86+
8387 console . log ( `Received URL: ${ url } ` ) ;
8488
8589 const browser = await puppeteer . launch ( {
@@ -96,16 +100,21 @@ export default class SaveUrl {
96100 console . log ( `New Page created.` ) ;
97101 page . setUserAgent ( userAgent ) ;
98102
99- console . log ( `User agent set.` ) ;
100- page . setViewport ( { width, height } ) ;
103+ if ( mobile ) {
104+ console . log ( `User agent set.` ) ;
105+ page . setViewport ( { width, height } ) ;
106+ }
101107 console . log ( `Screen Size set.` ) ;
102108 await page . goto ( url , { waitUntil : "networkidle2" } ) ;
103109 console . log ( `Url loaded.` ) ;
104110
105111 await sleep ( timeout ) ;
106112 console . log ( `Taking screenshot.` ) ;
107113
108- const screen = await page . screenshot ( ) as Buffer ;
114+ const screen = asPdf
115+ ? await page . pdf ( asPdf ) as Buffer
116+ : await page . screenshot ( ) as Buffer ;
117+
109118 console . log ( `Sending screenshot.` ) ;
110119 const body = screen . toString ( "base64" ) ;
111120 await browser . close ( ) ;
You can’t perform that action at this time.
0 commit comments