GoogleChrome / lighthouse

Automated auditing, performance metrics, and best practices for the web.
https://developer.chrome.com/docs/lighthouse/overview/
Apache License 2.0
28.47k stars 9.39k forks source link

Lighthouse has made an error in ubuntu 14.04 #3585

Closed mzkmzk closed 7 years ago

mzkmzk commented 7 years ago

I encountered some problems when using lighthouse at ubuntu14.04

eg: method <= browser ERR:error Audits.getEncodedResponse +75ms and method <= browser ERR:error Network.getResponseBody +10ms

Linux OS

> lsb_release  -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 14.04.5 LTS
Release:    14.04
Codename:   trusty

node version

> node -v
v8.3.0

chrome

> /usr/bin/chromium-browser  --version
Chromium 61.0.3163.100 Built on Ubuntu , running on Ubuntu 14.04

lighthouse:

> lighthouse --version
2.5.0

but run it's has some error

Lighthouse does not seem to get the contents of the response so that a similar method <= browser ERR: error Audits.getEncodedResponse this error

> lighthouse http://www.xunlei.com   --chrome-flags="--headless" --chrome-flags="--disable-setuid-sandbox"

 ChromeLauncher Waiting for browser. +0ms
  ChromeLauncher Waiting for browser... +2ms
  ChromeLauncher Waiting for browser..... +552ms
  ChromeLauncher Waiting for browser....... +503ms
  ChromeLauncher Waiting for browser.......✓ +2ms
  Lighthouse:warn The URL provided should be on HTTPS +614ms
  Lighthouse:warn Performance stats will be skewed redirecting from HTTP to HTTPS. +2ms
  status Initializing… +458ms
  status Loading page & waiting for onload URL, Viewport, ViewportDimensions, ThemeColor, Manifest, ChromeConsoleMessages, ImageUsage, Accessibility, EventListeners, AnchorsWithNoRelNoopener, AppCacheManifest, DOMStats, JSLibraries, OptimizedImages, PasswordInputsWithPreventedPaste, ResponseCompression, TagsBlockingFirstPaint, WebSQL +412ms
  Driver:warn Timed out waiting for page load. Moving on... +30s
  statusEnd Loading page & waiting for onload +1ms
  status Retrieving trace +1ms
  status Retrieving devtoolsLog and network records +10s
  status Retrieving: URL +93ms
  status Retrieving: Viewport +1ms
  status Retrieving: ViewportDimensions +68ms
  status Retrieving: ThemeColor +11ms
  status Retrieving: Manifest +4ms
  status Retrieving: ChromeConsoleMessages +8ms
  status Retrieving: ImageUsage +2ms
  status Retrieving: Accessibility +289ms
  status Retrieving: EventListeners +692ms
  status Retrieving: AnchorsWithNoRelNoopener +602ms
  status Retrieving: AppCacheManifest +5ms
  status Retrieving: DOMStats +3ms
  status Retrieving: JSLibraries +21ms
  status Retrieving: OptimizedImages +17ms
  method <= browser ERR:error Audits.getEncodedResponse  +75ms
  status Retrieving: PasswordInputsWithPreventedPaste +2s
  status Retrieving: ResponseCompression +2ms
  method <= browser ERR:error Network.getResponseBody  +10ms
  status Retrieving: TagsBlockingFirstPaint +0ms
  status Retrieving: WebSQL +10ms
  status Loading page & waiting for onload ServiceWorker, Offline, StartUrl +1s
  statusEnd Loading page & waiting for onload +928ms
  status Retrieving devtoolsLog and network records +11ms
  status Retrieving: ServiceWorker +25ms
  status Retrieving: Offline +1ms
  status Retrieving: StartUrl +256ms
  status Loading page & waiting for onload HTTPRedirect, HTMLWithoutJavaScript +1s
  statusEnd Loading page & waiting for onload +564ms
  status Retrieving devtoolsLog and network records +1ms
  status Retrieving: HTTPRedirect +4ms
  status Retrieving: HTMLWithoutJavaScript +38ms
  status Disconnecting from browser... +139ms
  status Analyzing and running audits... +666ms
  status Evaluating: Uses HTTPS +1ms
  status Evaluating: Redirects HTTP traffic to HTTPS +715ms
  status Evaluating: Registers a service worker +1ms
  status Evaluating: Responds with a 200 when offline +1ms
  status Evaluating: Has a `<meta name="viewport">` tag with `width` or `initial-scale` +0ms
  status Evaluating: Contains some content when JavaScript is not available +75ms
  status Evaluating: First meaningful paint +1ms
  status Evaluating: Page load is fast enough on 3G +672ms
  status Evaluating: Perceptual Speed Index +60ms
  status Evaluating: Screenshot Thumbnails +1s
  status Evaluating: Estimated Input Latency +839ms
  status Evaluating: No browser errors logged to the console +143ms
  status Evaluating: Keep server response times low (TTFB) +11ms
  status Evaluating: First Interactive (beta) +1ms
  status Evaluating: Consistently Interactive (beta) +1ms
  status Evaluating: User Timing marks and measures +7ms
  status Evaluating: Critical Request Chains +35ms
  status Evaluating: User can be prompted to Install the Web App +92ms
  status Evaluating: Configured for a custom splash screen +23ms
  status Evaluating: Address bar matches brand colors +1ms
  status Evaluating: Manifest's `short_name` won't be truncated when displayed on homescreen +1ms
  status Evaluating: Content is sized correctly for the viewport +0ms
  status Evaluating: Uses Images with appropriate aspect ratio +0ms
  status Evaluating: Avoids deprecated APIs +13ms
  status Evaluating: Site works cross-browser +3ms
  status Evaluating: Page transitions don't feel like they block on the network +0ms
  status Evaluating: Each page has a URL +1ms
  status Evaluating: `[accesskey]` values are unique. +0ms
  status Evaluating: `[aria-*]` attributes match their roles. +0ms
  status Evaluating: `[role]`s have all required `[aria-*]` attributes. +0ms
  status Evaluating: Elements with `[role]` that require specific children `[role]`s, are present. +1ms
  status Evaluating: `[role]`s are contained by their required parent element. +0ms
  status Evaluating: `[role]` values are valid. +0ms
  status Evaluating: `[aria-*]` attributes have valid values. +0ms
  status Evaluating: `[aria-*]` attributes are valid and not misspelled. +0ms
  status Evaluating: `<audio>` elements contain a `<track>` element with `[kind="captions"]`. +1ms
  status Evaluating: Buttons have an accessible name. +0ms
  status Evaluating: The page contains a heading, skip link, or landmark region. +0ms
  status Evaluating: Background and foreground colors have a sufficient contrast ratio. +0ms
  status Evaluating: `<dl>`'s contain only properly-ordered `<dt>` and `<dd>` groups, `<script>` or `<template>` elements. +0ms
  status Evaluating: Definition list items are wrapped in `<dl>` elements. +0ms
  status Evaluating: Document has a `<title>` element. +1ms
  status Evaluating: `[id]` attributes on the page are unique. +0ms
  status Evaluating: `<frame>` or `<iframe>` elements have a title. +0ms
  status Evaluating: `<html>` element has a `[lang]` attribute. +0ms
  status Evaluating: `<html>` element has a valid value for its `[lang]` attribute. +0ms
  status Evaluating: Image elements have `[alt]` attributes. +1ms
  status Evaluating: `<input type="image">` elements have `[alt]` text. +0ms
  status Evaluating: Form elements have associated labels. +0ms
  status Evaluating: Presentational `<table>` elements avoid using `<th>`, `<caption>` or the `[summary]` attribute. +0ms
  status Evaluating: Links have a discernible name. +0ms
  status Evaluating: Lists contain only `<li>` elements and script supporting elements (`<script>` and `<template>`). +1ms
  status Evaluating: List items (`<li>`) are contained within `<ul>` or `<ol>` parent elements. +0ms
  status Evaluating: The document does not use `<meta http-equiv="refresh">`. +0ms
  status Evaluating: `[user-scalable="no"]` is not used in the `<meta name="viewport">` element and the `[maximum-scale]` attribute is not less than 5. +0ms
  status Evaluating: `<object>` elements have `[alt]` text. +0ms
  status Evaluating: No element has a `[tabindex]` value greater than 0. +0ms
  status Evaluating: Cells in a `<table>` element that use the `[headers]` attribute only refer to other cells of that same table. +1ms
  status Evaluating: `<th>` elements and elements with `[role="columnheader"/"rowheader"]` have data cells they describe. +0ms
  status Evaluating: `[lang]` attributes have a valid value. +0ms
  status Evaluating: `<video>` elements contain a `<track>` element with `[kind="captions"]`. +0ms
  status Evaluating: `<video>` elements contain a `<track>` element with `[kind="description"]`. +0ms
  status Evaluating: Avoids enormous network payloads +1ms
  status Evaluating: Offscreen images +61ms
  status Evaluating: Serve images as WebP +45ms
  status Evaluating: Optimize images +1ms
  status Evaluating: Enable text compression +41ms
  Runner:warn ResponseCompression gatherer, required by audit uses-request-compression, encountered an error: Protocol error (Network.getResponseBody): No resource with given identifier found +8ms
  uses-request-compression:warn Caught exception: Required ResponseCompression gatherer encountered an error: Protocol error (Network.getResponseBody): No resource with given identifier found +19ms
  status Evaluating: Properly size images +0ms
  status Evaluating: Avoids Application Cache +6ms
  status Evaluating: Avoids an excessive DOM size +0ms
  status Evaluating: Opens external anchors using `rel="noopener"` +67ms
  status Evaluating: Avoids requesting the geolocation permission on page load +2ms
  status Evaluating: Reduce render-blocking stylesheets +3ms
  status Evaluating: Avoids `document.write()` +1ms
  status Evaluating: Avoids Mutation Events in its own scripts +1ms
  status Evaluating: Avoids front-end JavaScript libraries with known security vulnerabilities +1s
  status Evaluating: Avoids WebSQL DB +30ms
  status Evaluating: Avoids requesting the notification permission on page load +1ms
  status Evaluating: Allows users to paste into password fields +0ms
  status Evaluating: Reduce render-blocking scripts +0ms
  status Evaluating: Uses HTTP/2 for its own resources +11ms
  status Evaluating: Uses passive listeners to improve scrolling performance +31ms
  status Generating results... +1ms
  Printer domhtml output written to /var/www/html/k-performance/test_demo/www.xunlei.com_2017-10-17_16-17-26.report.html +1s
  CLI Protip: Run lighthouse with `--view` to immediately open the HTML report in your browser +6ms
  ChromeLauncher Killing Chrome instance 20030 +20ms
patrickhulce commented 7 years ago

@mzkmzk does the audit show an error or still produce results? (you'd be looking for a performance opportunity with a red error message)

Right now we do some feature detection and have a fallback path if that command fails, so the message itself in the logs should not be a concern. By the way, I noticed your running it with headless so be warned that the savings reported will be understated since throttling is not supported! See the docs for more.

mzkmzk commented 7 years ago

ok, thanks!

I tried the code: https://github.com/GoogleChrome/lighthouse/blob/master/docs/headless-chrome.md#node.

const lighthouse = require('lighthouse');
const chromeLauncher = require('chrome-launcher');

function launchChromeAndRunLighthouse(url, flags = {}, config = null) {
  return chromeLauncher.launch(flags).then(chrome => {
    flags.port = chrome.port;
    return lighthouse(url, flags, config).then(results =>
      chrome.kill().then(() => results));
  });
}

const flags = {
  chromeFlags: ['--headless']
};

launchChromeAndRunLighthouse('http://act.vip.xunlei.com/pc/kn/2017/wky/index.html', flags).then(results => {
    results.artifacts = 'ignore'
    results.reportCategories = 'ignore '
   console.log(JSON.stringify(results, null, 4))
});

Run the code three times, the results obtained here

  1. https://github.com/mzkmzk/demo-404mzk-com/blob/master/performance/test/test1.json
  2. https://github.com/mzkmzk/demo-404mzk-com/blob/master/performance/test/test2.json
  3. https://github.com/mzkmzk/demo-404mzk-com/blob/master/performance/test/test3.json

First , this error has appeared three times,

"consistently-interactive": {
            "score": null,
            "displayValue": "",
            "rawValue": null,
            "error": true,
            "debugString": "Audit error: Main thread activity continued through the end of the trace recording. Consistently Interactive requires a minimum of 5 seconds of both main thread idle and network idle.",
           ...
        },

however, other errors of first-interactive、consistently-interactive、offscreen-images and load-fast-enough-for-pwa appeared in the third time.

"first-interactive": {
    ....
    "error": true,
     "debugString": "Audit error: The main thread was busy for the entire trace recording. First Interactive requires the main thread to be idle for several seconds.",
    ...
}

"consistently-interactive": {
    ...
    "error": true,
     "debugString": "Audit error: Main thread activity continued through the end of the trace recording. Consistently Interactive requires a minimum of 5 seconds of both main thread idle and network idle.",
    ...
}

 "offscreen-images": {
    ...
     "error": true,
      "debugString": "Audit error: The main thread was busy for the entire trace recording. First Interactive requires the main thread to be idle for several seconds.",
    ...
}

"load-fast-enough-for-pwa": {
    ...
    "error": true,
     "debugString": "Audit error: The main thread was busy for the entire trace recording. First Interactive requires the main thread to be idle for several seconds.",
    ...
}

Is my CPU the worst?

> lscpu
Architecture:          x86_64
CPU op-mode(s):        32-bit, 64-bit
Byte Order:            Little Endian
CPU(s):                1
On-line CPU(s) list:   0
Thread(s) per core:    1
Core(s) per socket:    1
Socket(s):             1
NUMA node(s):          1
Vendor ID:             GenuineIntel
CPU family:            6
Model:                 62
Stepping:              4
CPU MHz:               2600.092
BogoMIPS:              5200.18
Hypervisor vendor:     Xen
Virtualization type:   full
L1d cache:             32K
L1i cache:             32K
L2 cache:              256K
L3 cache:              20480K
NUMA node0 CPU(s):     0
patrickhulce commented 7 years ago

We're working on improving our error messages here to be clearer, but that error message you receive isn't a Lighthouse error, it just means that the page you audited was running lots of JavaScript and didn't quiet down within our time limit. You can try to raise the time limit via the flag maxWaitForLoad. You can also try another simpler page like example.com to make sure your setup is working first.

mzkmzk commented 7 years ago

Oh, you’re right. I tried https://example.com, the report of running was normal. It proved that the lighthouse of my machine could analyze the simple webpage. However, the maxWaitForLoad settings were not seem to work, and I still received similar error messages when I raised the time limit to 60s via the flag maxWaitForLoad.

"script-blocking-first-paint": {
       ...
       "error": true,
       "debugString": "Audit error: Required TagsBlockingFirstPaint gatherer encountered an error: The asynchronous expression exceeded the allotted time of 60s",
    ...

Should I upgrade my computer configuration?Or should I continue arise the time limit via the flag maxWaitForLoad?

The following is my demo code:

const lighthouse = require('lighthouse');
const chromeLauncher = require('chrome-launcher');
const config = require('./lighthouse.config.js');
function launchChromeAndRunLighthouse(url, flags = {}, config = null) {
  return chromeLauncher.launch(flags).then(chrome => {
    flags.port = chrome.port;
    return lighthouse(url, flags, config).then(results =>
      chrome.kill().then(() => results));
  });
}

const flags = {
  chromeFlags: ['--headless'],
  maxWaitForLoad: 1000 * 60
};

launchChromeAndRunLighthouse('http://act.vip.xunlei.com/pc/kn/2017/wky/index.html', flags, config).then(results => {
    results.artifacts = 'ignore'
    results.reportCategories = 'ignore '
   console.log(JSON.stringify(results, null, 4))
});
patrickhulce commented 7 years ago

Strange, I'm experiencing intermittent failures of that page to load, but I'm unable to reproduce when the page loads successfully. The error you're experiencing would typically suggest either

Since I'm unable to reproduce with the page when it loads, and it looks like you're running in a server environment, neither of these seem to apply. My last remaining thoughts are that it might be something headless related. Have you tried auditing this page without the --headless flag using xvfb or something similar?

mzkmzk commented 7 years ago

Thank you for your suggestions, I think the most fundamental reason probably is my low server configuration. The problem may be solved when I upgrade my server configuration. Thank you for your help within this week.

fahdjamy commented 4 years ago

How do I run the file??????

connorjclark commented 4 years ago

Please open a new issue for your new problem.