I want to use puppeteer, lighthouse and want to login into the application using the automation. After login in I want to generate the lighthouse report for that page.
Is it possible?
If yes, what is the correct process/configuration.
Also want to know if the lighthouse has its own context during the execution?
import lighthouse from 'lighthouse';
import * as chromeLauncher from 'chrome-launcher';
import {launch} from 'puppeteer';
// import { desktopConfig } from 'lighthouse';
const browser = await launch();
const page = await browser.newPage();
await page.goto("https://example.com/");
console.log("Data entered 1");
await page.type("#USER_ID", "Ltsupport1");
await page.type("#USER_PASSWORD", "Secure124$");
await page.$eval("#TENNANT_ID", (element) => (element.value = ""));
console.log("Data entered 2");
// Send keys to the element
await page.type("#TENNANT_ID", "BOYD");
const element = await page.waitForSelector(
"tbody > tr:nth-child(8) > td:nth-child(3)"
);
const browserWSEndpoint = browser.wsEndpoint();
const chromePort = browserWSEndpoint.match(/:(d+)/)[1];
const chrome = await chromeLauncher.launch({chromeFlags: ['--headless']});
const options = {logLevel: 'info', output: 'html', onlyCategories: ['performance'], port: chromePort};
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.finalDisplayedUrl);
console.log('Performance score was', runnerResult.lhr.categories.performance.score * 100);