UNPKG

frontend-performance-analyzer

Version:
208 lines (146 loc) • 5.84 kB
# āš”ļø 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