Skip to main content
The Lighthouse Node module lets you run audits from JavaScript code and consume results as structured data. This is useful when you need to integrate Lighthouse into a custom script, build tool, or CI system.

Basic usage

Install Lighthouse as a project dependency:
Then run it programmatically:

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

Or from Node:

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:
The --ignore-certificate-errors flag disables TLS validation for all content loaded by the page, including third-party scripts and iframes. This opens the page to man-in-the-middle attacks. Only use this flag in controlled development environments.

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 sets auditMode to the directory containing the artifacts:
Then run with the config path:
Artifact files must use .trace.json and .devtoolslog.json extensions. The DevtoolsLog is captured from the Chrome Network and Page domains.