I am using the lighthouse node module to measure the performance of my application pages. I have written a small node script that would use this module to measure the performance of the multiple pages of my application. To run the script with the user session I am first opening the Chrome instance in a debug mode and then with the app URL I am establishing the user session and further using the port I am running the script with the CLI command to measure the performance of the application. The function code is as follows
function runLighthouse(url, pageName) {
return new Promise((resolve, reject) => {
const reportPath = `report-${encodeURIComponent(pageName)}.html`;
const chromeFlags = `--window-size=1920,1080`; // Adjust the viewport size as needed
const lighthouseProcess = spawn('lighthouse', [
url,
'--output=html',
'--only-categories=performance',
'--port',
port,
'--chrome-flags',
chromeFlags,
'--max-wait-for-load=60000',
`--output-path=${reportPath}`
]);
lighthouseProcess.stdout.on('data', (data) => {});
lighthouseProcess.stderr.on('data', (data) => {
const errorOutput = data.toString();
console.error(`Lighthouse measurement error: ${errorOutput}`);
});
lighthouseProcess.on('close', (code) => {
if (code === 0) {
console.log(`Lighthouse measurement completed for ${pageName}`);
resolve(reportPath); // Resolve with the path of the HTML report
} else {
console.error(`Lighthouse measurement failed for ${pageName}`);
reject(new Error(`Lighthouse process exited with code ${code}`));
}
});
})
Now the issue I am facing with this is The LCP reading I am getting in the HTML report is very high compared to when I measure the same using the lighthouse tool. I am not sure through script why that reading is too high.