GoogleChrome / lighthouse
- понедельник, 23 мая 2016 г. в 03:11:44
JavaScript
auditing and performance metrics for Progressive Web Apps
Stops you crashing into the rocks; lights the way
status: prototype extension and CLI available for testing
Requires Chrome version 52 or higher
chrome.google.com/webstore/detail/lighthouse/blipmdconlkpinefehnmjammfjpmpbjk
Requires Node version 5 or higher
npm install -g GoogleChrome/lighthouse
# Start Chrome with a few flags
npm explore -g lighthouse -- npm run chrome
# Kick off a lighthouse run
lighthouse https://airhorner.com/
# see flags and options
lighthouse --help
git clone https://github.com/GoogleChrome/lighthouse
cd lighthouse
npm install
npm link
Some basic unit tests forked are in /test
and run via mocha. eslint is also checked for style violations.
# lint and test all files
npm test
# watch for file changes and run tests
# Requires http://entrproject.org : brew install entr
npm run watch
## run linting and unit tests seprately
npm run lint
npm run unit
The same audits are run against from a Chrome extension. See ./extension.
Some incomplete notes
install_to_homescreen
) and applying weighting and overall scoring.chrome.debuggger
API when in the Chrome extension.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:// 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');
querySelector
method that can be used along with a getAttribute
method to read values.The return value of each audit takes this shape:
Promise.resolve({
name: 'audit-name',
tags: ['what have you'],
description: 'whatnot',
// value: The score. Typically a boolean, but can be number 0-100
value: 0,
// rawValue: Could be anything, as long as it can easily be stringified and displayed,
// e.g. 'your score is bad because you wrote ${rawValue}'
rawValue: {},
// debugString: Some *specific* error string for helping the user figure out why they failed here.
// The reporter can handle *general* feedback on how to fix, e.g. links to the docs
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.
// Whatever is in `rawValue` and `score` would be N/A in these cases
fault: 'some reason the audit has failed you, Anakin'
});
The .eslintrc
defines all.
We're using JSDoc along with closure annotations. Annotations encouraged for all contributions.
const
> let
> var
. Use const
wherever possible. Save var
for emergencies only.
The traceviewer-based trace processor from node-big-rig was forked into Lighthouse. Additionally, the DevTools' Timeline Model is available as well. There may be advantages for using one model over another.
To update traceviewer source:
# 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