Skip to content

Commit 89af8d5

Browse files
committed
fix: pass x-api-header
1 parent 0c12e21 commit 89af8d5

1 file changed

Lines changed: 19 additions & 7 deletions

File tree

src/microlink.js

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff 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+
1119
export 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

0 commit comments

Comments
 (0)