Let's suppose I'd only like to get the first-meaningful-paint
metric from Google Lighthouse.
I'm using the below snippet of code, which does a full audit (which takes too long, since I'm only interested in one metric). How can I change the below code to tell Lighthouse to only get one metric for me?
(Source code snippet based on this)
const puppeteer = require('puppeteer');
const lighthouse = require('lighthouse');
const urlLib = require('url').URL;
async function run() {
const browser = await puppeteer.launch({
headless: false,
defaultViewport: null
});
const { lhr } = await lighthouse("https://www.google.com", {
port: (new urlLib(browser.wsEndpoint())).port,
logLevel: 'info',
output: 'json'
});
console.log(lhr);
}
run();
Inside the settings
object of the configuration, you can specify which audits to run. When calling lighthouse
, the configuration is provided as third argument (more information in the docs).
Code Sample
lighthouse('...', { /* ... */ }, {
extends: 'lighthouse:default',
settings: {
onlyAudits: ['first-meaningful-paint'],
}
});
This will only run the first-meaningful-paint
audit.