forked from akshayp7/playwright-typescript-playwright-test
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLighthouse.js
25 lines (19 loc) · 1.09 KB
/
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
const fs = require('fs');
const lighthouse = require('lighthouse');
const chromeLauncher = require('chrome-launcher');
(async () => {
const chrome = await chromeLauncher.launch({chromeFlags: ['--headless']});
const options = {logLevel: 'info',output: 'html',onlyCategories: ['performance'],port: chrome.port};
// Below configuration is for Desktop mode
const config = { extends: 'lighthouse:default', settings: {formFactor: 'desktop', screenEmulation:{mobile:false}} }
// Below configuration is for Mobile devices
// const config = { extends: 'lighthouse:default', settings: {formFactor: 'mobile', screenEmulation:{mobile:true}} }
const runnerResult = await lighthouse('https://www.google.com',options,config);
// `.report` is the HTML report as a string
const reportHtml = runnerResult.report;
fs.writeFileSync('LighthouseReport.html', reportHtml);
// `.lhr` is the Lighthouse Result as a JS object
console.log('Report is done for', runnerResult.lhr.finalUrl);
console.log('Performance score was', runnerResult.lhr.categories.performance.score * 100);
await chrome.kill();
})();