frontend-performance-analyzer
Version:
CLI to analyze frontend performance using Lighthouse
208 lines (146 loc) ⢠5.84 kB
Markdown
# ā”ļø Frontend Performance Analyzer
**A simple CLI tool to analyze frontend performance using Lighthouse and Puppeteer.**
- š§ Built for developers who care about performance
- š Powered by headless Chrome and real metrics
- š¦ Publish-ready for NPM usage
- š Automatically validates URL accessibility before analysis
- š Comprehensive progress reporting and analysis summaries
- š Multiple export formats (HTML, JSON, Markdown)
## š¦ Installation
You can run it instantly via `npx`:
```bash
npx frontend-performance-analyzer --url https://example.com
```
Or install it globally:
```bash
npm install -g frontend-performance-analyzer
```
## š Usage
### Analyze a Single URL
```bash
frontend-performance-analyzer --url https://example.com
```
### Analyze Multiple URLs
```bash
frontend-performance-analyzer --url https://example.com https://github.com
```
### Load URLs from File
```bash
frontend-performance-analyzer --input urls.txt
# or
frontend-performance-analyzer --input urls.json
```
### Export Reports
```bash
# Save HTML report (automatically named based on URL)
frontend-performance-analyzer --url https://example.com --output
# Save JSON report to file
frontend-performance-analyzer --url https://example.com --json-file report.json
# Save Markdown summary (automatically named based on URL)
frontend-performance-analyzer --url https://example.com --markdown
# Output raw JSON to console
frontend-performance-analyzer --url https://example.com --json
```
### Logging and Verbosity Options
```bash
# Verbose output with debugging details
frontend-performance-analyzer --url https://example.com --verbose
# Minimal output (errors and final results only)
frontend-performance-analyzer --url https://example.com --silent
```
### Use Performance Threshold
Exit with failure if score is below threshold:
```bash
frontend-performance-analyzer --url https://example.com --threshold 85
```
## š URL Validation & Accessibility
The tool automatically:
- ā
Validates URL format before analysis
- š Checks URL accessibility with HEAD requests and 10-second timeout
- ā ļø Warns about inaccessible URLs and skips them
- š Provides detailed progress reporting during analysis
- š Continues analysis even if some URLs fail
## š Sample Output
```
š Checking URL accessibility...
Checking https://example.com... ā
ā
1 URL(s) are accessible and will be analyzed
š Starting Lighthouse analysis...
[1/1] š Analyzing https://example.com...
āā Launching browser...
āā Analysis complete!
š Performance Metrics for https://example.com
Score: 93/100
First Contentful Paint: 1.2 s
Speed Index: 1.9 s
Largest Contentful Paint: 1.4 s
Time to Interactive: 1.6 s
Total Blocking Time: 30 ms
Cumulative Layout Shift: 0.01
š Analysis Summary:
ā
Successful: 1
ā Failed: 0
š Total analyzed: 1
```
## š Input File Formats
- `.txt`: List of URLs separated by new lines
- `.json`: JSON array of URLs, e.g. `["https://example.com", "https://github.com"]`
## š Export Formats
### HTML Reports
- Full Lighthouse HTML report with all details
- Automatically named based on URL (e.g., `example_com.html`)
### JSON Reports
- Structured JSON output with performance metrics
- Includes timestamp, tool version, and detailed scores
- Supports both single URL and batch analysis
- Contains all Lighthouse categories (Performance, Accessibility, Best Practices, SEO, PWA)
### Markdown Reports
- Human-readable performance summary
- Core Web Vitals breakdown with visual indicators
- Performance opportunities and diagnostics
- Category scores with emoji indicators
- Automatically named based on URL (e.g., `example_com.md`)
## šØ Error Handling & Validation
The tool provides comprehensive validation and error handling:
- **Invalid URLs**: validates URL format before processing
- **Inaccessible URLs**: tests connectivity with HEAD requests and 10-second timeout
- **File validation**: ensures input files exist and have correct extensions (.txt or .json)
- **Threshold validation**: validates threshold values are between 0-100
- **Graceful failures**: continues analysis even if some URLs fail
- **Lighthouse warnings**: filters internal Lighthouse warnings for cleaner output
- **Browser management**: proper cleanup of browser instances
## š§ Advanced Features
### Logging Levels
- **Normal**: standard output with progress indicators
- **Verbose** (`--verbose`): detailed debugging information including timing
- **Silent** (`--silent`): minimal output, errors and final results only
### Performance Monitoring
- Tracks analysis time per URL
- Reports overall performance (URLs/second)
- Browser launch and close timing
- Accessibility check timing
### Batch Processing
- Supports multiple URL analysis in a single run
- Consolidated JSON export for batch results
- Individual file exports for each URL
- Progress tracking with clear indicators
## š Development
Clone the repo and run:
```bash
npm install
node cli.js --url https://example.com
```
### Project Structure
```
āāā cli.js # Main CLI entry point
āāā lib/
ā āāā lighthouse.js # Lighthouse analysis logic
ā āāā logger.js # Logging utilities
ā āāā url-utils.js # URL validation and processing
āāā report-formatters/
āāā console.js # Console output formatting
āāā json.js # JSON export functionality
āāā markdown.js # Markdown report generation
```
## š License
MIT Ā© 2025 Oleksandr Zadvornyi