Created
September 29, 2020 14:19
-
-
Save svkrclg/e1b6b9fdf335d6ec285bf9a0f5815072 to your computer and use it in GitHub Desktop.
Run specific chrome binary
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs'); | |
const lighthouse = require('lighthouse'); | |
const chromeLauncher = require('chrome-launcher'); | |
(async () => { | |
const chrome = await chromeLauncher.launch({chromePath: "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"}); //Specify chrome binary path to run lighthouse. | |
const options = {logLevel: 'info', output: 'html', onlyCategories: ['performance'], port: chrome.port}; | |
const runnerResult = await lighthouse('https://example.com', options); | |
// `.report` is the HTML report as a string | |
const reportHtml = runnerResult.report; | |
fs.writeFileSync('lhreport.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(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment