Lighthouse automation not working properly

Viewed 16

I've this simple code from lighthouse. And when I'm using desktop configuration then somehow it automatically redirects to the mobile page and take out the mobile analytics.

const fs = require("fs");
const lighthouse = require("lighthouse");
const chromeLauncher = require("chrome-launcher");

(async () => {
    const URL = "https://www.youtube.com/";
    const chrome = await chromeLauncher.launch({
        chromeFlags: ["--ignore-certificate-errors"],
        port: 61736,
    });
    const options = {
        extends: "lighthouse:default",
        logLevel: "info",
        output: "html",
        onlyCategories: ["performance"],
        port: chrome.port,
        preset: "desktop",
    };

    const runnerResult = await lighthouse(URL, 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
        // runnerResult.lhr.categories.performance
    );

    await chrome.kill();
})();

However, if I'm using this command lighthouse https://www.youtube.com/ --preset=desktop --chrome-flags=ignore-certificate-errors --port=61736 then it's taking out the analytics of desktop only. Not sure why?

How can I take out the desktop analytics through code?

0 Answers
Related