Skip to content

Instantly share code, notes, and snippets.

@svkrclg
Created September 29, 2020 14:19
Show Gist options
  • Save svkrclg/e1b6b9fdf335d6ec285bf9a0f5815072 to your computer and use it in GitHub Desktop.
Save svkrclg/e1b6b9fdf335d6ec285bf9a0f5815072 to your computer and use it in GitHub Desktop.
Run specific chrome binary
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