File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -8,16 +8,28 @@ const formatBytes = bytes => {
88 return `${ ( bytes / ( 1024 * 1024 ) ) . toFixed ( 2 ) } MB`
99}
1010
11+ const toApiHeaders = headers => {
12+ const result = { }
13+ for ( const [ key , value ] of Object . entries ( headers ) ) {
14+ result [ `x-api-header-${ key } ` ] = String ( value )
15+ }
16+ return result
17+ }
18+
1119export const screenshot = async ( url , { log = noop , ...opts } = { } ) => {
1220 log ( `→ requesting screenshot for ${ url } ` )
1321 const start = Date . now ( )
14- const { screenshot : screenshotOpts , ...rest } = opts
15- const { data } = await mql ( url , {
16- waitForTimeout : 3000 ,
17- meta : false ,
18- screenshot : { fullPage : true , type : 'png' , ...screenshotOpts } ,
19- ...rest
20- } )
22+ const { screenshot : screenshotOpts , headers, ...rest } = opts
23+ const { data } = await mql (
24+ url ,
25+ {
26+ waitForTimeout : 3000 ,
27+ meta : false ,
28+ screenshot : { fullPage : true , type : 'png' , ...screenshotOpts } ,
29+ ...rest
30+ } ,
31+ headers ? { headers : toApiHeaders ( headers ) } : undefined
32+ )
2133 log ( `← microlink responded for ${ url } in ${ Date . now ( ) - start } ms` )
2234
2335 const imageUrl = data ?. screenshot ?. url
You can’t perform that action at this time.
0 commit comments