2016-03-08 00:52:24 +03:00
# lighthouse
2016-04-04 23:51:15 +03:00
> Stops you crashing into the rocks; lights the way
2016-03-08 00:52:24 +03:00
2016-05-20 00:25:19 +03:00
![image ](https://cloud.githubusercontent.com/assets/39191/15410166/30c658e2-1dcd-11e6-99da-8996be5429b6.png )
![image ](https://cloud.githubusercontent.com/assets/39191/15410190/502b2d52-1dcd-11e6-9d82-5de8742180bd.png )
2016-03-19 22:15:22 +03:00
2016-03-16 03:57:46 +03:00
[![Build Status ](https://travis-ci.org/GoogleChrome/lighthouse.svg?branch=master )](https://travis-ci.org/GoogleChrome/lighthouse)
2016-05-27 11:03:19 +03:00
[![Coverage Status ](https://coveralls.io/repos/github/GoogleChrome/lighthouse/badge.svg?branch=master )](https://coveralls.io/github/GoogleChrome/lighthouse?branch=master)
2016-03-16 03:57:46 +03:00
2016-05-20 00:28:04 +03:00
_status: prototype extension and CLI available for testing_
2016-05-20 00:25:19 +03:00
2016-05-20 00:28:04 +03:00
## Install Chrome extension
2016-03-08 00:52:24 +03:00
2016-05-20 03:20:41 +03:00
Requires Chrome version 52 or higher
[chrome.google.com/webstore/detail/lighthouse/blipmdconlkpinefehnmjammfjpmpbjk ](https://chrome.google.com/webstore/detail/lighthouse/blipmdconlkpinefehnmjammfjpmpbjk )
2016-05-20 00:28:04 +03:00
## Install CLI
2016-05-20 03:20:41 +03:00
Requires Node version 5 or higher
2016-03-08 00:52:24 +03:00
```sh
2016-04-22 19:43:07 +03:00
npm install -g GoogleChrome/lighthouse
2016-04-14 11:01:51 +03:00
```
2016-03-13 03:42:33 +03:00
2016-04-14 11:01:51 +03:00
## Run
```sh
2016-03-28 22:11:50 +03:00
# Start Chrome with a few flags
2016-05-03 21:39:35 +03:00
npm explore -g lighthouse -- npm run chrome
2016-03-28 22:11:50 +03:00
2016-03-22 21:40:31 +03:00
# Kick off a lighthouse run
lighthouse https://airhorner.com/
2016-03-26 02:55:10 +03:00
# see flags and options
lighthouse --help
2016-03-08 00:52:24 +03:00
```
2016-04-14 11:01:51 +03:00
## Develop
#### Setup
```sh
git clone https://github.com/GoogleChrome/lighthouse
cd lighthouse
2016-06-14 15:28:04 +03:00
# will be cleaner soon.
cd lighthouse-core
2016-04-14 11:01:51 +03:00
npm install
2016-06-14 15:28:04 +03:00
cd ../lighthouse-cli/
npm install
# npm link # nah...
# just use `node lighthouse-cli/index.js` for now
# probably very temporary
cd lighthouse-core
2016-04-14 11:01:51 +03:00
npm link
2016-06-14 15:28:04 +03:00
cd ../lighthouse-cli/
npm link lighthouse-core
2016-04-14 11:01:51 +03:00
```
2016-03-26 02:55:10 +03:00
2016-03-13 03:39:51 +03:00
## Tests
2016-03-08 00:52:24 +03:00
2016-03-22 21:40:31 +03:00
Some basic unit tests forked are in `/test` and run via mocha. eslint is also checked for style violations.
2016-03-08 00:52:24 +03:00
2016-03-13 03:39:51 +03:00
```js
2016-03-29 00:01:54 +03:00
# lint and test all files
2016-03-29 03:33:32 +03:00
npm test
2016-03-29 00:01:54 +03:00
2016-04-25 03:45:33 +03:00
# watch for file changes and run tests
# Requires http://entrproject.org : brew install entr
npm run watch
2016-03-29 00:01:54 +03:00
## run linting and unit tests seprately
npm run lint
npm run unit
2016-03-13 03:39:51 +03:00
```
2016-03-08 00:52:24 +03:00
2016-04-25 03:45:33 +03:00
## Chrome Extension
2016-06-22 19:07:23 +03:00
The same audits are run against from a Chrome extension. See [./extension ](https://github.com/GoogleChrome/lighthouse/tree/master/lighthouse-extension ).
2016-04-25 03:45:33 +03:00
2016-03-31 02:17:41 +03:00
## Architecture
2016-04-25 03:45:33 +03:00
_Some incomplete notes_
2016-03-31 02:17:41 +03:00
#### Components
* **Driver** - Interfaces with Chrome Debugging Protocol
* **Gathers** - Requesting data from the browser (and maybe post-processing)
* **Artifacts** - The output of gatherers
* **Audits** - Non-performance evaluations of capabilities and issues. Includes a raw value and score of that value.
* **Metrics** - Performance metrics summarizing the UX
* **Diagnoses** - The perf problems that affect those metrics
* **Aggregators** - Pulling audit results, grouping into user-facing components (eg. `install_to_homescreen` ) and applying weighting and overall scoring.
2016-04-08 20:46:08 +03:00
### Protocol
2016-04-25 03:45:33 +03:00
* _Interacting with Chrome:_ The Chrome protocol connection maintained via [chrome-remote-interface ](https://github.com/cyrus-and/chrome-remote-interface ) for the CLI and [`chrome.debuggger` API ](https://developer.chrome.com/extensions/debugger ) when in the Chrome extension.
2016-04-08 20:46:08 +03:00
* _Event binding & domains_: Some domains must be `enable()` d so they issue events. Once enabled, they flush any events that represent state. As such, network events will only issue after the domain is enabled. All the protocol agents resolve their `Domain.enable()` callback _after_ they have flushed any pending events. See example:
```js
// will NOT work
driver.sendCommand('Security.enable').then(_ => {
driver.on('Security.securityStateChanged', state => { /* ... */ });
})
// WILL work! happy happy. :)
driver.on('Security.securityStateChanged', state => { /* ... */ }); // event binding is synchronous
driver.sendCommand('Security.enable');
```
2016-04-20 20:47:14 +03:00
* _Debugging the protocol_: Read [Better debugging of the Protocol ](https://github.com/GoogleChrome/lighthouse/issues/184 ).
2016-04-08 20:46:08 +03:00
2016-03-31 02:17:41 +03:00
### Gatherers
2016-04-25 03:45:33 +03:00
* _Reading the DOM:_ We prefer reading the DOM right from the browser (See #77 ). The driver exposes a `querySelector` method that can be used along with a `getAttribute` method to read values.
2016-03-31 02:17:41 +03:00
2016-04-05 00:26:45 +03:00
### Audits
The return value of each audit takes this shape:
```js
Promise.resolve({
name: 'audit-name',
tags: ['what have you'],
description: 'whatnot',
// value: The score. Typically a boolean, but can be number 0-100
2016-04-25 03:45:33 +03:00
value: 0,
// rawValue: Could be anything, as long as it can easily be stringified and displayed,
2016-04-05 00:26:45 +03:00
// e.g. 'your score is bad because you wrote ${rawValue}'
2016-04-25 03:45:33 +03:00
rawValue: {},
// debugString: Some *specific* error string for helping the user figure out why they failed here.
2016-04-05 00:26:45 +03:00
// The reporter can handle *general* feedback on how to fix, e.g. links to the docs
2016-04-25 03:45:33 +03:00
debugString: 'Your manifest 404ed'
// fault: Optional argument when the audit doesn't cover whatever it is you're doing,
// e.g. we can't parse your particular corner case out of a trace yet.
2016-04-05 00:26:45 +03:00
// Whatever is in `rawValue` and `score` would be N/A in these cases
fault: 'some reason the audit has failed you, Anakin'
});
```
2016-03-31 02:17:41 +03:00
## Code Style
2016-03-22 21:40:31 +03:00
The `.eslintrc` defines all.
2016-03-29 00:01:54 +03:00
We're using [JSDoc ](http://usejsdoc.org/ ) along with [closure annotations ](https://developers.google.com/closure/compiler/docs/js-for-compiler ). Annotations encouraged for all contributions.
2016-03-22 21:40:31 +03:00
`const` > `let` > `var` . Use `const` wherever possible. Save `var` for emergencies only.
2016-03-13 03:39:51 +03:00
## Trace processing
2016-03-08 00:52:24 +03:00
2016-03-22 21:40:31 +03:00
The traceviewer-based trace processor from [node-big-rig ](https://github.com/GoogleChrome/node-big-rig/tree/master/lib ) was forked into Lighthouse. Additionally, the [DevTools' Timeline Model ](https://github.com/paulirish/devtools-timeline-model ) is available as well. There may be advantages for using one model over another.
2016-05-11 09:35:31 +03:00
**To update traceviewer source:**
```sh
# if not already there, clone catapult and copy license over
git clone --depth=1 https://github.com/catapult-project/catapult.git third_party/src/catapult
cp third_party/src/catapult/LICENSE third_party/traceviewer-js/
# pull for latest
git -C "./third_party/src/catapult/" pull
# run our conversion script
node scripts/build-traceviewer-module.js
```
2016-05-20 00:25:19 +03:00
< p align = "center" >
< img src = "https://cloud.githubusercontent.com/assets/883126/13900813/10a62a14-edcc-11e5-8ad3-f927a592eeb0.png" height = "300px" >
< / p >