forked from choraria/pptr-io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmetrics.js
31 lines (27 loc) · 827 Bytes
/
metrics.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
const puppeteer = require("puppeteer-core");
const chrome = require("chrome-aws-lambda");
module.exports = async (req, res) => {
try {
const url = req.query.url;
const browser = await puppeteer.launch({
args: [...chrome.args, "--hide-scrollbars", "--disable-web-security"],
defaultViewport: chrome.defaultViewport,
executablePath: await chrome.executablePath,
ignoreHTTPSErrors: true,
});
const page = await browser.newPage();
await page.goto(url);
const metrics = await page.metrics();
await browser.close();
res.statusCode = 200;
res.setHeader("Content-Type", `application/json`);
res.end(JSON.stringify(metrics));
} catch (err) {
console.log(err);
res.statusCode = 500;
res.json({
error: err.toString(),
});
res.end();
}
};