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.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/GoogleChrome/lighthouse/llms.txt
Use this file to discover all available pages before exploring further.
Basic usage
Install Lighthouse as a project dependency:Function signature
| Parameter | Type | Required | Description |
|---|---|---|---|
url | string | No (if using auditMode) | The URL to audit. |
flags | object | No | Run options that override config settings. |
config | object | No | Full Lighthouse configuration object. Defaults to the built-in default config. |
page | Puppeteer.Page | No | An existing Puppeteer page to use instead of launching a new browser. |
Promise<RunnerResult | undefined>.
Key flags
| Flag | Type | Description |
|---|---|---|
logLevel | 'silent' | 'error' | 'warn' | 'info' | 'verbose' | Controls log output. Use 'info' to see progress. |
output | 'html' | 'json' | 'csv' | Report format. The result is returned as a string in .report. |
onlyCategories | string[] | Limit audits to the specified categories: 'performance', 'accessibility', 'best-practices', 'seo'. |
port | number | DevTools Protocol port of the Chrome instance to connect to. You must launch Chrome separately. |
Differences from CLI flags
Some CLI flags behave differently or are ignored when using the Node module.| CLI flag | Behavior in Node module |
|---|---|
port | Only specifies which port to connect to. Chrome is not launched automatically. |
chromeFlags | Ignored. Chrome is not launched for you. |
outputPath | Ignored. Output is returned as a string in .report. |
saveAssets | Ignored. Artifacts are returned in .artifacts. |
view | Ignored. Use the open npm package if you want this behavior. |
enableErrorReporting | Ignored. Error reporting is always disabled in the Node module. |
listAllAudits | Ignored. Not relevant in programmatic use. |
listTraceCategories | Ignored. Not relevant in programmatic use. |
configPath | Ignored. Pass the config object as the third argument to lighthouse(). |
preset | Ignored. Pass the config object as the third argument to lighthouse(). |
verbose | Ignored. Use logLevel: 'verbose' instead. |
quiet | Ignored. Use logLevel: 'silent' instead. |
The RunnerResult object
lighthouse() resolves to a RunnerResult with three properties:
| Property | Type | Description |
|---|---|---|
.report | string | string[] | The formatted report. A string for a single output format, or string[] when multiple formats are requested. |
.lhr | LH.Result | The full Lighthouse Result object as a plain JS object. Contains all scores, audit results, and metadata. |
.artifacts | LH.Artifacts | Raw gathered artifacts from the page (traces, network logs, DOM snapshots, etc.). |
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:Enable USB debugging on the device
On the Android device, go to Settings > Developer options and enable USB debugging.
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.