LighthouseWrapper PowerShell Module

A simple, reusable PowerShell module for running Lighthouse audits and processing results.

Installation

# Import the module
Import-Module .\scripts\LighthouseWrapper.psd1

Prerequisites

Quick Start

Basic Usage

# Simple audit
$result = Invoke-LighthouseAudit -URL 'https://example.com'
Show-LighthouseResults -Result $result

Save Reports

# Generate JSON and HTML reports
$result = Invoke-LighthouseAudit `
    -URL 'https://example.com' `
    -OutputPath 'benchmarks/my-audit' `
    -HTMLReport `
    -OpenReport

Mobile Testing

# Mobile device preset
$result = Invoke-LighthouseAudit -URL 'https://example.com' -Device mobile

Compare Results

# Compare local vs production
$local = Invoke-LighthouseAudit -URL 'http://localhost:4000'
$prod = Invoke-LighthouseAudit -URL 'https://example.com'

Compare-LighthouseResults -Results @($local, $prod)

Export to CSV

# Audit multiple URLs and export scores
$urls = @('url1', 'url2', 'url3')
$results = $urls | ForEach-Object { Invoke-LighthouseAudit -URL $_ }
$results | Get-LighthouseScores | Export-Csv 'scores.csv'

Available Functions

Invoke-LighthouseAudit

Runs a Lighthouse audit on a URL.

Parameters:

Returns: PSCustomObject with audit results

Show-LighthouseResults

Displays formatted audit results in the console.

Parameters:

Compare-LighthouseResults

Compares multiple audit results side-by-side.

Parameters:

Get-LighthouseScores

Extracts scores as a simple object for export/logging.

Parameters:

Returns: PSCustomObject with score percentages

Testing

Run the test script to validate functionality:

.\scripts\Test-Lighthouse.ps1 -URL 'http://localhost:4000' -Verbose

Examples

See scripts/examples/lighthouse-usage-examples.ps1 for comprehensive usage examples.

Troubleshooting

“No Chrome or Edge installation found”

“Lighthouse failed with exit code 1”

Local server audits fail

Module Structure

scripts/
├── LighthouseWrapper.psm1      # Main module file
├── LighthouseWrapper.psd1      # Module manifest
├── Test-Lighthouse.ps1         # Test script
├── examples/
│   └── lighthouse-usage-examples.ps1
└── README-LighthouseWrapper.md # This file

Version History