-
Notifications
You must be signed in to change notification settings - Fork 36
/
handler.js
43 lines (39 loc) · 984 Bytes
/
handler.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
'use strict';
const chromium = require('chrome-aws-lambda');
const puppeteer = chromium.puppeteer;
module.exports.index = async (event, context) => {
let browser = null;
try {
browser = await puppeteer.launch({
defaultViewport:{width:1024,height:800},
headless: true,
executablePath: await chromium.executablePath,
args: chromium.args,
});
const page = await browser.newPage();
await page.goto(event['queryStringParameters'].address, {
waitUntil: ['domcontentloaded', 'networkidle0'],
});
const image = await page.screenshot({
clip: { x: 0, y: 0, width: 1024, height: 800 },
encoding: 'base64'
});
return {
statusCode: 200,
body: image,
headers: {
'Content-Type': 'image/png',
},
isBase64Encoded: true
};
} catch (error) {
console.error(error);
return {
statusCode: 500
};
}
finally{
if(browser)
await browser.close();
}
};