-
Notifications
You must be signed in to change notification settings - Fork 14
/
lighthouse.js
30 lines (28 loc) · 878 Bytes
/
lighthouse.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
const { chromium } = require('playwright');
const lighthouse = require('lighthouse');
(async () => {
const url = 'https://gocovid19.netlify.app/';
const browserServer = await chromium.launchServer();
const wsEndpoint = browserServer.wsEndpoint();
// Use web socket endpoint later to establish a connection.
const browser = await chromium.connect({ wsEndpoint });
// console.log(wsEndpoint);
const { lhr } = await lighthouse(url, {
port: new URL(wsEndpoint).port,
output: 'json',
logLevel: 'info',
});
const scores = Object.keys(lhr.categories).map((c) => {
const categorey = lhr.categories[c];
const { title, id, score } = categorey;
return {
title,
id,
score: score * 100,
audits: categorey.auditRefs.length,
};
});
console.table(scores);
await browserServer.close();
await browser.close();
})();