question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Different audit results between DevTools and Node module

See original GitHub issue

Provide the steps to reproduce

  1. I’m running LH on Chrome Canary (Version 78.0.3866.0 (Official Build) canary (64-bit)) using the DevTools with the following settings:

image

  1. I’m running LH programmatically using chrome-launcher, here my dependencies:
  • lighthouse 5.2.0 image

The code:

import * as ChromeLauncher from "chrome-launcher";
import * as lighthouse from 'lighthouse';
import * as LighthouseLogger from 'lighthouse-logger';
import * as ReportGenerator from 'lighthouse/lighthouse-core/report/report-generator';
import {DeviceType} from "../models/device-type.enum";
import TrackingUrlService from "./api/tracking-url.service";
import Report from "../models/api/report.model";
import EventEmitterHandler from "../helpers/eventEmitterHandler";

export default class LighthouseService {

    constructor() {
    }

    public static async launchHeadlessChromeAndRunLighthouse(config = null) {

        /**
         * Adjustments needed for DevTools network throttling to simulate
         * more realistic network conditions.
         * @see https://crbug.com/721112
         * @see https://docs.google.com/document/d/10lfVdS1iDWCRKQXPfbxEn4Or99D64mvNlugP1AQuFlE/edit
         * @see https://github.com/WPO-Foundation/webpagetest/blob/master/www/settings/connectivity.ini.sample
         */
        const DEVTOOLS_RTT_ADJUSTMENT_FACTOR = 3.75;
        const DEVTOOLS_THROUGHPUT_ADJUSTMENT_FACTOR = 0.9;
        const TARGET_LATENCY = 70;
        const TARGET_DOWNLOAD_THROUGHPUT = Math.floor(12 * 1024);
        const TARGET_UPLOAD_THROUGHPUT = Math.floor(12 * 1024);

        let flagsDesktop: any = {
            logLevel: 'info',
            throttlingMethod: 'provided',
            // disableDeviceEmulation: true,
            // disableCpuThrottling: true,
            disableStorageReset: true,
            emulatedFormFactor: 'desktop',
            port: null,
            throttling: {
                rttMs: 0,
                throughputKbps: 0,
                requestLatencyMs: 0,
                downloadThroughputKbps: 0,
                uploadThroughputKbps: 0,
                cpuSlowdownMultiplier: 0,
            }
        };

        let flagsMobile: any = {
            logLevel: 'info',
            throttlingMethod: 'devtools',
            // disableDeviceEmulation: false,
            // disableCpuThrottling: false,
            disableStorageReset: true,
            emulatedFormFactor: 'mobile',
            port: null,
            throttling: {
                rttMs: TARGET_LATENCY,
                throughputKbps: TARGET_DOWNLOAD_THROUGHPUT,
                requestLatencyMs: TARGET_LATENCY * DEVTOOLS_RTT_ADJUSTMENT_FACTOR,
                downloadThroughputKbps: TARGET_DOWNLOAD_THROUGHPUT * DEVTOOLS_THROUGHPUT_ADJUSTMENT_FACTOR,
                uploadThroughputKbps: TARGET_UPLOAD_THROUGHPUT * DEVTOOLS_THROUGHPUT_ADJUSTMENT_FACTOR,
                cpuSlowdownMultiplier: 4,
            }
        };

        LighthouseLogger.setLevel('info');

        let trackingUrlsList = await TrackingUrlService.getTrackingUrls();

        if (trackingUrlsList && trackingUrlsList.length > 0) {

            let chrome: any = await ChromeLauncher.launch({chromeFlags: ['--headless', '--no-sandbox', '--disable-setuid-sandbox', '--window-size=1366,768']});

            try {

                flagsDesktop.port = chrome.port;
                flagsMobile.port = chrome.port;

                for (let i = 0; i < trackingUrlsList.length; i++) {

                    let results = [];
                    let parsedData = [];
                    const url = trackingUrlsList[i].requestedUrl;
                    const trackingId = trackingUrlsList[i].trackingId;

                    console.log('--- Auditing desktop on ', url);
                    results.push({result: await lighthouse(url, flagsDesktop, config), device: DeviceType.Desktop, trackingId});
                    console.log('--- Auditing mobile on ', url);
                    results.push({result: await lighthouse(url, flagsMobile, config), device: DeviceType.Mobile, trackingId});

                    results.forEach(async (data: any) => {
                        console.log('Generating html report...');
                        let html = ReportGenerator.generateReport(data.result.lhr, 'html');
                        console.log('Parsing data...');
                        parsedData.push({data: LighthouseService.parseData(data), html});

                    });

                    EventEmitterHandler.getInstance().emit('reportsReadyForProcessing', parsedData);
                }

                await chrome.kill();
            } catch (e) {
                chrome.kill().then(
                    () => {
                        throw e;
                    },
                    console.error
                );
            }
        }
    }

    private static parseData(data): any {
       ...
    }
}

What is the current behavior?

There is a big difference between both TTI:

image

The runtime settings are the same fro both:

image

What is the expected behavior?

I expected to get similar results in both cases and that’s not the case;

Environment Information

  • Affected Channels:
  • Lighthouse version: 5.2.0
  • Node.js version: 11.10.0
  • Operating System: macOS Mojave 10.14.6

Related issues

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8

github_iconTop GitHub Comments

1reaction
rainergpcommented, Jul 30, 2019

Thank you so much @patrickhulce . Yes, for what I need I must use puppeteer, so far this is handling the issue:

let chrome: any = await ChromeLauncher.launch({
  chromeFlags: ['--no-sandbox', '--disable-setuid-sandbox', '--window-size=1366,768']
});

const resp = await util.promisify(request)(`http://localhost:${chrome.port}/json/version`);
const {webSocketDebuggerUrl} = JSON.parse(resp.body);
const browser = await puppeteer.connect({browserWSEndpoint: webSocketDebuggerUrl});

const page = (await browser.pages())[0];
await page.goto('https://www.test.com', {waitUntil: 'networkidle2'});

await lighthouse(page.url(), flags, config)

I’m closing the issue, thank you for your help.

1reaction
rainergpcommented, Jul 29, 2019

I’m sorry @patrickhulce I pushed the unfinished description by mistake. Now you have the full description.

Read more comments on GitHub >

github_iconTop Results From Across the Web

NPM Audit: How to Scan Packages for Security Vulnerabilities
NPM audit scans your project for security vulnerabilities and outputs a report with tips on how to fix them. Learn how to use...
Read more >
Lighthouse overview - Chrome Developers
In Chrome DevTools. Easily audit pages that require authentication, and read your reports in a user-friendly format. ; From the command line.
Read more >
lighthouse - npm
Lighthouse analyzes web apps and web pages, collecting modern performance metrics and insights on developer best practices. Using Lighthouse.
Read more >
Build a Node.js Tool to Record and Compare Google ...
In this tutorial, I'll show you step by step how to create a simple tool in Node.js to run Google Lighthouse audits via...
Read more >
Google Lighthouse Audit Guide - Electriq Marketing
Chrome DevTools: for user-friendly reports and to easily authenticate pages for auditing; Node Module: integrate Lighthouse into continuous integration systems ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found