Basic usage
Install Lighthouse as a project dependency:Function signature
Returns
Promise<RunnerResult | undefined>.
Key flags
Differences from CLI flags
Some CLI flags behave differently or are ignored when using the Node module.The RunnerResult object
lighthouse() resolves to a RunnerResult with three properties:
Custom configuration
Pass a config object as the third argument to extend or replace the default configuration:Testing on a mobile device
To run Lighthouse against a real Android device connected via USB:1
Install and start adb
2
Enable USB debugging on the device
On the Android device, go to Settings > Developer options and enable USB debugging.
3
Forward the DevTools port
4
Run Lighthouse against the forwarded port
Testing a site with an untrusted certificate
When Chrome encounters an untrusted TLS certificate, it cannot load the page and most audit results will be errors. If you control the certificate (for example, a self-signed cert for local development), the recommended solution is to add it to your system’s trusted certificate store. Alternatively, you can instruct Chrome to ignore certificate errors:Using Lighthouse as a trace processor
Lighthouse can analyze pre-collected trace and DevTools log files without launching a browser. This is useful for reprocessing data collected by other tools such as WebPageTest or ChromeDriver. Provide a config that setsauditMode to the directory containing the artifacts:
.trace.json and .devtoolslog.json extensions. The DevtoolsLog is captured from the Chrome Network and Page domains.