Here's how to generate a Lighthouse report using the CLI:
Installation
First, install Lighthouse globally via npm:
npm install -g lighthouse
Basic Usage
Generate a report for any URL:
lighthouse https://example.com
This creates an HTML report in your current directory with a timestamp filename like example.com_2024-05-29_12-30-45.report.html.
Common Options
Output Formats
Generate different report formats:
# HTML report (default)
lighthouse https://example.com --output=html
# JSON report
lighthouse https://example.com --output=json
# CSV report
lighthouse https://example.com --output=csv
# Multiple formats
lighthouse https://example.com --output=json --output=html
Specify Output Path
Save the report with a custom filename:
lighthouse https://example.com --output-path=./my-report
Categories
Run specific audits only:
# Performance only
lighthouse https://example.com --only-categories=performance
# Multiple categories
lighthouse https://example.com --only-categories=performance,accessibility,seo
Available categories: performance, accessibility, best-practices, seo, pwa
Device Emulation
Test mobile or desktop experience:
# Mobile (default)
lighthouse https://example.com --form-factor=mobile
# Desktop
lighthouse https://example.com --form-factor=desktop
Chrome Options
Run in headless mode or specify Chrome path:
# Headless Chrome (default)
lighthouse https://example.com --chrome-flags="--headless"
# With specific Chrome installation
lighthouse https://example.com --chrome-path="/path/to/chrome"
Advanced Examples
Full Command with Multiple Options
lighthouse https://example.com \
--output=json \
--output=html \
--output-path=./reports/mysite \
--only-categories=performance,seo \
--form-factor=desktop \
--throttling-method=devtools \
--chrome-flags="--headless"
Authenticated Pages
For pages behind authentication:
# Basic auth
lighthouse https://example.com --extra-headers='{"Authorization":"Basic base64encodedstring"}'
# Cookie auth
lighthouse https://example.com --extra-headers='{"Cookie":"sessionid=abc123"}'
Performance Budgets
Test against performance budgets:
lighthouse https://example.com --budget-path=./budget.json
Example budget.json:
[
{
"path": "/*",
"resourceSizes": [
{
"resourceType": "script",
"budget": 300
},
{
"resourceType": "total",
"budget": 1000
}
]
}
]
Viewing Reports
After generation:
- HTML: Open the
.html file in any browser
- JSON: Parse programmatically or view in a JSON viewer
- CSV: Import into spreadsheet applications
Automation Tip
Create a simple bash script for regular audits:
#!/bin/bash
DATE=$(date +%Y%m%d_%H%M%S)
lighthouse https://example.com \
--output=json \
--output=html \
--output-path=./reports/report_$DATE
This generates timestamped reports for tracking performance over time.