Skip to content

Instantly share code, notes, and snippets.

@paulirish
Created November 17, 2021 23:02
Show Gist options
  • Save paulirish/92901337b1397b4dafe20e4210b155a2 to your computer and use it in GitHub Desktop.
Save paulirish/92901337b1397b4dafe20e4210b155a2 to your computer and use it in GitHub Desktop.
run lighthouse headlessly
'use strict';
import fs from 'fs';
import puppeteer from 'puppeteer';
import {navigation} from 'lighthouse/lighthouse-core/fraggle-rock/api.js';
// Run Lighthouse headlessly, just Performance
(async function() {
const browser = await puppeteer.launch({headless: true});
const page = await browser.newPage();
const configContext = {settingsOverrides: {onlyCategories: ['performance'], output: 'html'}};
const {lhr, artifacts, report} = await navigation({url: 'http://localhost:8080', page, configContext});
await browser.close();
fs.writeFileSync('bg-lh.report.html', report);
console.log({lhr, artifacts});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment