Chrome must be installed on the machine running Lighthouse. The
chrome-launcher package handles launching and connecting to it automatically.1
Install dependencies
Install
lighthouse and chrome-launcher as dev dependencies.2
Write your first script
The following example launches a headless Chrome instance, runs a Lighthouse audit, saves an HTML report, and prints the performance score.Run it with:
audit.js
3
Access the report and result object
The
lighthouse() function returns a RunnerResult with two key properties:Access category scores and individual audit results directly from
.lhr:4
Run performance-only audits
Pass You can also pass multiple categories:
onlyCategories in the options object to limit which audit categories run. This reduces run time significantly when you only need specific data.Configuration
Pass a config object as the third argument tolighthouse() to customize audits beyond what flags allow:
lighthouse:default to build on the standard configuration, or omit it to start from scratch.
See Configuration overview for all available options, and Node API reference for the full API surface.