2017-05-28 01:37:25 +03:00
# Lighthouse [![Linux Build Status](https://img.shields.io/travis/GoogleChrome/lighthouse/master.svg)](https://travis-ci.org/GoogleChrome/lighthouse) [![Windows Build Status](https://img.shields.io/appveyor/ci/paulirish/lighthouse/master.svg)](https://ci.appveyor.com/project/paulirish/lighthouse/branch/master) [![Coverage Status](https://img.shields.io/coveralls/GoogleChrome/lighthouse/master.svg)](https://coveralls.io/github/GoogleChrome/lighthouse?branch=master) [![NPM lighthouse package](https://img.shields.io/npm/v/lighthouse.svg)](https://npmjs.org/package/lighthouse)
2016-03-08 00:52:24 +03:00
2016-10-07 01:33:39 +03:00
> Lighthouse analyzes web apps and web pages, collecting modern performance metrics and insights on developer best practices.
2016-05-20 00:25:19 +03:00
2017-05-24 03:29:08 +03:00
## Using Lighthouse in Chrome DevTools
2016-03-08 00:52:24 +03:00
2017-05-24 03:29:08 +03:00
Lighthouse is integrated directly into the Chrome Developer Tools, under the "Audits" panel.
2016-05-20 00:28:04 +03:00
2017-09-12 02:51:55 +03:00
**Installation**: install [Chrome ](https://www.google.com/chrome/browser ).
2016-09-08 21:18:59 +03:00
2018-05-26 00:55:15 +03:00
**Run it**: open Chrome DevTools, select the Audits panel, and hit "Run audits".
2016-05-20 03:20:41 +03:00
2018-05-26 00:55:15 +03:00
< img width = "500px" alt = "Lighthouse integration in Chrome DevTools" src = "https://user-images.githubusercontent.com/2301202/40556658-4ef7d128-6002-11e8-903e-5224894a7cca.png" >
2016-05-20 03:20:41 +03:00
2017-05-24 03:29:08 +03:00
## Using the Chrome extension
2016-03-13 03:42:33 +03:00
2017-05-24 03:29:08 +03:00
**Installation**: [install the extension ](https://chrome.google.com/webstore/detail/lighthouse/blipmdconlkpinefehnmjammfjpmpbjk ) from the Chrome Web Store.
2017-01-25 22:46:04 +03:00
2017-05-24 03:29:08 +03:00
**Run it**: follow the [extension quick-start guide ](https://developers.google.com/web/tools/lighthouse/#extension ).
2016-10-31 21:21:08 +03:00
2017-05-24 03:29:08 +03:00
## Using the Node CLI
2016-10-24 17:45:01 +03:00
2018-05-26 00:55:15 +03:00
_Lighthouse requires Node 8 LTS (8.9) or later._
2016-10-24 17:45:01 +03:00
2017-05-24 03:29:08 +03:00
**Installation**:
2016-10-22 00:59:36 +03:00
2016-08-31 10:22:50 +03:00
```sh
2017-05-24 03:29:08 +03:00
npm install -g lighthouse
# or use yarn:
# yarn global add lighthouse
2016-07-12 05:02:46 +03:00
```
2017-05-24 03:29:08 +03:00
**Run it**: `lighthouse https://airhorner.com/`
2017-03-08 04:36:38 +03:00
By default, Lighthouse writes the report to an HTML file. You can control the output format by passing flags.
2016-07-12 05:02:46 +03:00
2017-05-24 03:29:08 +03:00
### CLI options
2016-07-13 23:29:20 +03:00
```sh
$ lighthouse --help
lighthouse < url >
Logging:
2017-05-09 00:55:05 +03:00
--verbose Displays verbose logging [boolean]
--quiet Displays no progress, debug logs or errors [boolean]
2016-07-13 23:29:20 +03:00
Configuration:
2017-05-09 00:55:05 +03:00
--save-assets Save the trace contents & screenshots to disk [boolean]
--list-all-audits Prints a list of all available audits and exits [boolean]
--list-trace-categories Prints a list of all required trace categories and exits [boolean]
--additional-trace-categories Additional categories to capture with the trace (comma-delimited).
--config-path The path to the config JSON.
--chrome-flags Custom flags to pass to Chrome (space-delimited). For a full list of flags, see
2017-08-02 00:39:01 +03:00
http://peter.sh/experiments/chromium-command-line-switches/.
Environment variables:
CHROME_PATH: Explicit path of intended Chrome binary. If set must point to an executable of a build of
2018-06-11 21:38:51 +03:00
Chromium version 66.0 or later. By default, any detected Chrome Canary or Chrome (stable) will be launched.
2017-08-02 00:39:01 +03:00
[default: ""]
2018-01-06 00:03:44 +03:00
--port The port to use for the debugging protocol. Use 0 for a random port [default: 0]
2018-05-04 00:36:13 +03:00
--preset Use a built-in configuration. [choices: "full", "perf", "mixed-content"]
2018-01-06 00:03:44 +03:00
--hostname The hostname to use for the debugging protocol. [default: "localhost"]
2017-05-09 00:55:05 +03:00
--max-wait-for-load The timeout (in milliseconds) to wait before the page is considered done loading and the run should continue.
2018-01-06 00:03:44 +03:00
WARNING: Very high values can lead to large traces and instability [default: 45000]
--enable-error-reporting Enables error reporting, overriding any saved preference. --no-enable-error-reporting will do the opposite. More:
https://git.io/vFFTO
--gather-mode, -G Collect artifacts from a connected browser and save to disk. If audit-mode is not also enabled, the run will quit
early. [boolean]
--audit-mode, -A Process saved artifacts from disk [boolean]
2016-07-13 23:29:20 +03:00
Output:
2018-04-10 01:40:15 +03:00
--output Reporter for the results, supports multiple values [choices: "csv", "json", "html"] [default: "html"]
2017-05-09 00:55:05 +03:00
--output-path The file path to output the results. Use 'stdout' to write to stdout.
2018-04-10 01:40:15 +03:00
If using JSON or CSV output, default is stdout.
2017-05-09 00:55:05 +03:00
If using HTML output, default is a file in the working directory with a name based on the test URL and date.
2017-03-08 04:36:38 +03:00
If using multiple outputs, --output-path is ignored.
2017-05-09 00:55:05 +03:00
Example: --output-path=./lighthouse-results.html
--view Open HTML report in your browser [boolean]
2016-07-13 23:29:20 +03:00
Options:
2017-05-09 00:55:05 +03:00
--help Show help [boolean]
--version Show version number [boolean]
2017-08-29 03:05:56 +03:00
--blocked-url-patterns Block any network requests to the specified URL patterns [array]
2017-05-09 00:55:05 +03:00
--disable-storage-reset Disable clearing the browser cache and other storage APIs before a run [boolean]
--disable-device-emulation Disable Nexus 5X emulation [boolean]
2018-04-20 21:08:08 +03:00
--throttling-method Controls throttling method [choices: "devtools", "provided", "simulate"]
--throttling.rttMs Controls simulated network RTT (TCP layer)
--throttling.throughputKbps Controls simulated network download throughput
--throttling.requestLatencyMs Controls emulated network RTT (HTTP layer)
--throttling.downloadThroughputKbps Controls emulated network download throughput
--throttling.uploadThroughputKbps Controls emulated network upload throughput
--throttling.cpuSlowdownMultiplier Controls simulated + emulated CPU throttling
2018-01-19 22:50:32 +03:00
--extra-headers Set extra HTTP Headers to pass with request [string]
2017-05-09 00:55:05 +03:00
Examples:
lighthouse < url > --view Opens the HTML report in a browser after the run completes
lighthouse < url > --config-path=./myconfig.js Runs Lighthouse with your own configuration: custom audits, report
generation, etc.
lighthouse < url > --output=json --output-path=./report.json --save-assets Save trace, screenshots, and named JSON report.
2018-04-20 21:08:08 +03:00
lighthouse < url > --disable-device-emulation Disable device emulation and all throttling.
--throttling-method=provided
2017-05-09 00:55:05 +03:00
lighthouse < url > --chrome-flags="--window-size=412,732" Launch Chrome with a specific window size
lighthouse < url > --quiet --chrome-flags="--headless" Launch Headless Chrome, turn off logging
2018-01-19 22:50:32 +03:00
lighthouse < url > --extra-headers "{\"Cookie\":\"monster=blue\"}" Stringify\'d JSON HTTP Header key/value pairs to send in requests
lighthouse < url > --extra-headers=./path/to/file.json Path to JSON file of HTTP Header key/value pairs to send in requests
2017-05-09 00:55:05 +03:00
For more information on Lighthouse, see https://developers.google.com/web/tools/lighthouse/.
2016-07-13 23:29:20 +03:00
```
2017-03-04 03:54:07 +03:00
##### Output Examples
2018-01-06 00:03:44 +03:00
```sh
lighthouse
# saves `./<HOST>_<DATE>.report.html`
lighthouse --output json
# json output sent to stdout
lighthouse --output html --output-path ./report.html
# saves `./report.html`
2017-03-04 03:54:07 +03:00
2018-01-06 00:03:44 +03:00
# NOTE: specifying an output path with multiple formats ignores your specified extension for *ALL* formats
lighthouse --output json --output html --output-path ./myfile.json
# saves `./myfile.report.json` and `./myfile.report.html`
2017-03-04 03:54:07 +03:00
2018-01-06 00:03:44 +03:00
lighthouse --output json --output html
# saves `./<HOST>_<DATE>.report.json` and `./<HOST>_<DATE>.report.html`
2017-03-04 03:54:07 +03:00
2018-01-06 00:03:44 +03:00
lighthouse --output-path=~/mydir/foo.out --save-assets
# saves `~/mydir/foo.report.html`
# saves `~/mydir/foo-0.trace.json` and `~/mydir/foo-0.screenshots.html`
2017-03-04 03:54:07 +03:00
2018-01-06 00:03:44 +03:00
lighthouse --output-path=./report.json --output json
# saves `./report.json`
```
##### Lifecycle Examples
You can run a subset of Lighthouse's lifecycle if desired via the `--gather-mode` (`-G`) and `--audit-mode` (`-A`) CLI flags.
2017-02-07 04:28:42 +03:00
2018-01-06 00:03:44 +03:00
```sh
2018-05-26 00:55:15 +03:00
lighthouse http://example.com -G
2018-01-06 00:03:44 +03:00
# launches browser, collects artifacts, saves them to disk (in `./latest-run/`) and quits
2017-02-07 04:28:42 +03:00
2018-05-26 00:55:15 +03:00
lighthouse http://example.com -A
2018-01-06 00:03:44 +03:00
# skips browser interaction, loads artifacts from disk (in `./latest-run/`), runs audits on them, generates report
2018-05-26 00:55:15 +03:00
lighthouse http://example.com -GA
2018-01-06 00:03:44 +03:00
# Normal gather + audit run, but also saves collected artifacts to disk for subsequent -A runs.
2018-03-20 03:13:09 +03:00
# You can optionally provide a custom folder destination to -G/-A/-GA. Without a value, the default will be `$PWD/latest-run`.
lighthouse -GA=./gmailartifacts https://gmail.com
2018-01-06 00:03:44 +03:00
```
2017-02-07 04:28:42 +03:00
2017-10-27 03:01:03 +03:00
#### Notes on Error Reporting
The first time you run the CLI you will be prompted with a message asking you if Lighthouse can anonymously report runtime exceptions. The Lighthouse team uses this information to detect new bugs and avoid regressions. Opting out will not affect your ability to use Lighthouse in any way. [Learn more ](https://github.com/GoogleChrome/lighthouse/blob/master/docs/error-reporting.md ).
2017-02-15 21:21:25 +03:00
## Viewing a report
2017-05-24 03:29:08 +03:00
Lighthouse can produce a report as JSON or HTML.
2017-02-15 21:21:25 +03:00
HTML report:
2016-04-25 03:45:33 +03:00
2018-09-18 01:04:13 +03:00
![Lighthouse report ](/assets/example_audit.png )
2016-03-31 02:17:41 +03:00
2017-02-15 21:21:25 +03:00
### Online Viewer
2017-01-25 22:46:04 +03:00
2017-02-15 21:21:25 +03:00
Running Lighthouse with the `--output=json` flag generates a json dump of the run.
You can view this report online by visiting < https: / / googlechrome . github . io / lighthouse / viewer / >
and dragging the file onto the app. You can also use the "Export" button from the
top of any Lighthouse HTML report and open the report in the
[Lighthouse Viewer ](https://googlechrome.github.io/lighthouse/viewer/ ).
2016-03-31 02:17:41 +03:00
2017-02-15 21:21:25 +03:00
In the Viewer, reports can be shared by clicking the share icon in the top
right corner and signing in to GitHub.
2016-10-14 00:29:19 +03:00
2017-02-15 21:21:25 +03:00
> **Note**: shared reports are stashed as a secret Gist in GitHub, under your account.
2016-06-23 21:49:35 +03:00
2017-05-24 03:29:08 +03:00
## Docs & Recipes
2017-03-10 00:36:53 +03:00
2017-05-24 03:29:08 +03:00
Useful documentation, examples, and recipes to get you started.
**Docs**
- [Using Lighthouse programmatically ](./docs/readme.md#using-programmatically )
- [Testing a site with authentication ](./docs/readme.md#testing-on-a-site-with-authentication )
- [Testing on a mobile device ](./docs/readme.md#testing-on-a-mobile-device )
- [Lighthouse Architecture ](./docs/architecture.md )
**Recipes**
- [gulp ](docs/recipes/gulp ) - helpful for CI integration
- [Custom Audit example ](./docs/recipes/custom-audit ) - extend Lighthouse, run your own audits
**Videos**
2018-05-26 00:55:15 +03:00
The session from Google I/O 2018 covers the new performance engine, upcoming Lighthouse REST API, and using the Chrome UX report to evaluate real-user data.
[![Lighthouse @ Google I/O 2018 ](https://img.youtube.com/vi/UvK9zAsSM8Q/0.jpg )](https://www.youtube.com/watch?v=UvK9zAsSM8Q)
2017-05-24 03:29:08 +03:00
The session from Google I/O 2017 covers architecture, writing custom audits,
2017-10-27 19:56:08 +03:00
GitHub/Travis/CI integration, headless Chrome, and more:
2017-05-24 03:29:08 +03:00
2018-05-26 00:55:15 +03:00
[![Lighthouse @ Google I/O 2017 ](https://img.youtube.com/vi/NoRYn6gOtVo/0.jpg )](https://www.youtube.com/watch?v=NoRYn6gOtVo)
2017-05-24 03:29:08 +03:00
_click to watch the video_
2017-03-10 00:36:53 +03:00
2017-02-15 21:21:25 +03:00
## Develop
2016-06-23 21:49:35 +03:00
2017-05-24 03:29:08 +03:00
Read on for the basics of hacking on Lighthouse. Also see [Contributing ](./CONTRIBUTING.md )
for detailed information.
2017-02-15 21:21:25 +03:00
### Setup
2016-04-08 20:46:08 +03:00
2017-02-15 21:21:25 +03:00
```sh
2017-05-24 03:29:08 +03:00
# yarn should be installed first
2017-04-27 00:56:52 +03:00
2017-02-15 21:21:25 +03:00
git clone https://github.com/GoogleChrome/lighthouse
2016-04-08 20:46:08 +03:00
2017-02-15 21:21:25 +03:00
cd lighthouse
2017-06-05 21:23:58 +03:00
yarn
2017-04-26 22:41:01 +03:00
yarn install-all
2017-04-27 00:56:52 +03:00
yarn build-all
2016-04-08 20:46:08 +03:00
```
2017-01-25 22:46:04 +03:00
2017-02-15 21:21:25 +03:00
### Run
```sh
node lighthouse-cli http://example.com
2018-08-29 01:50:56 +03:00
# append --chrome-flags="--no-sandbox --headless --disable-gpu" if you run into problems connecting to Chrome
2016-04-05 00:26:45 +03:00
```
2018-08-29 01:50:56 +03:00
> **Getting started tip**: `node --inspect-brk lighthouse-cli http://example.com` to open up Chrome DevTools and step
2017-02-15 21:21:25 +03:00
through the entire app. See [Debugging Node.js with Chrome
DevTools](https://medium.com/@paul_irish/debugging-node-js-nightlies-with-chrome-devtools-7c4a1b95ae27#.59rma3ukm)
for more info.
2017-05-24 03:29:08 +03:00
### Tests
2016-05-11 09:35:31 +03:00
```sh
2017-02-15 21:21:25 +03:00
# lint and test all files
2017-04-26 22:41:01 +03:00
yarn test
2017-02-15 21:21:25 +03:00
# watch for file changes and run tests
# Requires http://entrproject.org : brew install entr
2017-04-26 22:41:01 +03:00
yarn watch
2017-02-15 21:21:25 +03:00
2017-05-24 03:29:08 +03:00
## run linting, unit, and smoke tests separately
2017-04-26 22:41:01 +03:00
yarn lint
yarn unit
2017-05-24 03:29:08 +03:00
yarn smoke
2017-05-02 02:46:13 +03:00
2018-05-26 00:55:15 +03:00
## run tsc compiler
yarn type-check
2016-05-11 09:35:31 +03:00
```
2016-05-20 00:25:19 +03:00
2017-05-24 23:32:54 +03:00
## Lighthouse Integrations
2018-05-21 20:04:54 +03:00
This section details services that have integrated Lighthouse data. If you're working on a cool project integrating Lighthouse and would like to be featured here, file an issue to this repo or tweet at us [@_____lighthouse ](https://twitter.com/____lighthouse?lang=en )!
2017-05-24 23:32:54 +03:00
2017-12-12 06:36:36 +03:00
* **[Calibre](https://calibreapp.com)** - Calibre is a web performance monitoring tool running Lighthouse continuously or on-demand via an API. Test using emulated devices and connection speeds from a number of geographical locations. Set budgets and improve performance with actionable guidelines. Calibre comes with a free 14-day trial.
2017-10-07 03:31:17 +03:00
2017-10-12 00:53:37 +03:00
* **[HTTPArchive](http://httparchive.org/)** - HTTPArchive tracks how the web is built by crawling 500k pages with Web Page Test, including Lighthouse results, and stores the information in BigQuery where it is [publicly available ](https://discuss.httparchive.org/t/quickstart-guide-to-exploring-the-http-archive/682 ).
2018-07-27 03:33:24 +03:00
* **[SpeedCurve](https://speedcurve.com)** — SpeedCurve is a tool for continuously monitoring web performance across different browsers, devices, and regions. It can aggregate any metric including Lighthouse scores across multiple pages and sites, and allows you to set performance budgets with Slack or email alerts. SpeedCurve is a paid product with a free 30-day trial.
2017-10-27 19:56:08 +03:00
* **[Treo](https://treo.sh)** - Treo is Lighthouse as a Service. It provides regression testing, geographical regions, custom networks, and integrations with GitHub & Slack. Treo is a paid product with plans for solo-developers and teams.
2017-05-24 23:32:54 +03:00
* **[Web Page Test](https://www.webpagetest.org)** — An [open source ](https://github.com/WPO-Foundation/webpagetest ) tool for measuring and analyzing the performance of web pages on real devices. Users can choose to produce a Lighthouse report alongside the analysis of WebPageTest results.
2018-05-21 20:04:54 +03:00
2017-05-24 03:29:08 +03:00
## Related Projects
2018-05-21 20:04:54 +03:00
Other awesome open source projects that use Lighthouse.
2017-02-15 21:21:25 +03:00
2017-05-24 23:32:54 +03:00
* **[webpack-lighthouse-plugin](https://github.com/addyosmani/webpack-lighthouse-plugin)** - run Lighthouse from a Webpack build.
* **[lighthouse-mocha-example](https://github.com/justinribeiro/lighthouse-mocha-example)** - gather performance metrics via Lighthouse and tests them in Mocha
* **[pwmetrics](https://github.com/paulirish/pwmetrics/)** - gather performance metrics
* **[lighthouse-hue](https://github.com/ebidel/lighthouse-hue)** - set the color of Philips Hue lights based on a Lighthouse score
2017-10-31 03:11:50 +03:00
* **[lighthouse-magic-light](https://github.com/manekinekko/lighthouse-magic-light)** set the color of the MagicLight Bluetooth Smart Light Bulb based on Lighthouse score
2017-05-24 23:32:54 +03:00
* **[lighthouse-batch](https://www.npmjs.com/package/lighthouse-batch)** - run Lighthouse over a number of sites and generate a summary of their metrics/scores.
2018-09-07 21:48:07 +03:00
* **[lighthouse-badges](https://github.com/emazzotta/lighthouse-badges)** - Generate gh-badges (shields.io) based on Lighthouse performance.
2017-05-24 23:32:54 +03:00
* **[lighthouse-cron](https://github.com/thearegee/lighthouse-cron)** - Cron multiple batch Lighthouse audits and emit results for sending to remote server.
2017-06-27 23:26:57 +03:00
* **[lightcrawler](https://github.com/github/lightcrawler)** - Crawl a website and run each page found through Lighthouse.
2018-05-17 00:52:46 +03:00
* **[lighthouse-lambda](https://github.com/joytocode/lighthouse-lambda)** - Run Lighthouse on AWS Lambda with prebuilt stable desktop Headless Chrome.
2018-05-26 00:55:15 +03:00
* **[lighthouse-security](https://github.com/voorhoede/lighthouse-security#readme)** - Run a set of security audits along with Lighthouse.
2018-05-21 20:04:54 +03:00
* **[Garie](https://github.com/boyney123/garie)** — An open source tool for monitoring performance using Lighthouse, PageSpeed Insights, [Prometheus ](https://prometheus.io/ ), [Grafana ](https://grafana.com/ ) and [Docker ](https://www.docker.com/ ).
2018-06-15 22:10:21 +03:00
* **[lighthouse-ci](https://github.com/andreasonny83/lighthouse-ci)** - Run Lighthouse and assert scores satisfy your custom thresholds.
2017-02-15 21:21:25 +03:00
## FAQ
2017-05-24 03:29:08 +03:00
### How does Lighthouse work?
2017-02-15 21:21:25 +03:00
See [Lighthouse Architecture ](./docs/architecture.md ).
2017-07-11 03:15:21 +03:00
### Can I configure the lighthouse run?
Yes! Details in [Lighthouse configuration ](./docs/configuration.md ).
2017-09-05 23:00:04 +03:00
### How does Lighthouse use network throttling, and how can I make it better?
2017-02-15 21:21:25 +03:00
2017-09-05 23:00:04 +03:00
Good question. Network and CPU throttling are applied by default in a Lighthouse run. The network
attempts to emulate 3G and the CPU is slowed down 4x from your machine's default speed. If you
prefer to run Lighthouse without throttling, you'll have to use the CLI and disable it with the
2018-05-26 00:55:15 +03:00
`--throttling.*` flags mentioned above.
2017-02-15 21:21:25 +03:00
2017-09-05 23:00:04 +03:00
Read more in our [guide to network throttling ](./docs/throttling.md ).
2017-02-15 21:21:25 +03:00
### Are results sent to a remote server?
Nope. Lighthouse runs locally, auditing a page using a local version of the Chrome browser installed the
machine. Report results are never processed or beaconed to a remote server.
2017-05-24 03:29:08 +03:00
### How do I author custom audits to extend Lighthouse?
2017-05-22 19:46:10 +03:00
2017-05-24 03:29:08 +03:00
> **Tip**: see [Lighthouse Architecture](./docs/architecture.md) for more information
on terminology and architecture.
2017-05-22 19:46:10 +03:00
2017-05-24 03:29:08 +03:00
Lighthouse can be extended to run custom audits and gatherers that you author.
This is great if you're already tracking performance metrics in your site and
want to surface those metrics within a Lighthouse report.
2017-05-22 19:46:10 +03:00
2017-05-24 03:29:08 +03:00
If you're interested in running your own custom audits, check out our
[Custom Audit Example ](./docs/recipes/custom-audit ) over in recipes.
### How do I contribute?
We'd love help writing audits, fixing bugs, and making the tool more useful!
See [Contributing ](./CONTRIBUTING.md ) to get started.
2017-05-22 19:46:10 +03:00
---
2016-05-20 00:25:19 +03:00
< p align = "center" >
2017-02-15 21:21:25 +03:00
< img src = "https://cloud.githubusercontent.com/assets/39191/22478294/23f662f6-e79e-11e6-8de3-ffd7be7bf628.png" alt = "Lighthouse logo" height = "150" >
2017-01-25 22:46:04 +03:00
< br >
2017-02-15 21:21:25 +03:00
< b > Lighthouse< / b > , ˈ lītˌhous (n): a < s > tower or other structure< / s > tool containing a beacon light
to warn or guide < s > ships at sea< / s > developers.
2016-05-20 00:25:19 +03:00
< / p >