Skip to content

Automated Lighthouse performance analysis with Python. Batch URL testing, Core Web Vitals monitoring, Full HD screenshots & clean CSV/HTML reports.

Notifications You must be signed in to change notification settings

manishsongirkar/lighthouse-automation-suite

Repository files navigation

πŸš€ Lighthouse Automation Suite

A comprehensive Python automation tool that analyzes website performance using Google Lighthouse via PageSpeed Insights and generates detailed reports.

πŸ“‹ Features

  • βœ… πŸ“Š Simple Performance Dashboard - Clean, focused performance overview
  • βœ… 🧹 Clean CSV Structure - CSV contains Core Web Vitals data
  • βœ… Mobile & Desktop Scores - Captures both device types
  • βœ… πŸ“Έ Full HD Screenshot Capture - Optional mobile and desktop screenshots
  • βœ… Automated PageSpeed Analysis - Tests multiple URLs automatically
  • βœ… 🧹 Streamlined architecture - Essential metrics without complexity
  • βœ… 🎨 Professional UI/UX - Single-focus design with Core Web Vitals
  • βœ… Batch Processing - Analyze hundreds of URLs with configurable delays
  • βœ… Smart URL Validation - Validates URLs and handles malformed entries
  • βœ… Cross-Platform - Dynamic paths work on Windows, macOS, and Linux
  • βœ… πŸ“Š Core Web Vitals matrix - Detailed performance metrics with color coding
  • βœ… πŸ”„ Clean CSV output - Essential performance data only

πŸ“Š What It Measures

Performance Scores (0-100)

  • Performance - Loading speed and optimization
  • Accessibility - Usability for users with disabilities
  • Best Practices - Modern web development standards
  • SEO - Search engine optimization factors

Core Web Vitals

  • First Contentful Paint (FCP) - Time to first content render
  • Largest Contentful Paint (LCP) - Time to largest content render
  • Total Blocking Time (TBT) - Main thread blocking time
  • Cumulative Layout Shift (CLS) - Visual stability metric
  • Speed Index - How quickly page contents are populated

🎨 Color Coding System

The HTML dashboard uses Google's official Core Web Vitals thresholds for color coding:

🟒 Good Performance (Green)

  • Performance Scores: β‰₯90
  • First Contentful Paint: ≀1.8s
  • Largest Contentful Paint: ≀2.5s
  • Total Blocking Time: ≀200ms
  • Cumulative Layout Shift: ≀0.1
  • Speed Index: ≀3.4s

🟑 Needs Improvement (Orange)

  • Performance Scores: 50-89
  • Core Web Vitals: Between good and poor thresholds

πŸ”΄ Poor Performance (Red)

  • Performance Scores: <50
  • First Contentful Paint: >3.0s
  • Largest Contentful Paint: >4.0s
  • Total Blocking Time: >600ms
  • Cumulative Layout Shift: >0.25
  • Speed Index: >5.8s

⚑ Quick Start

For experienced users who want to get started immediately:

# Clone the repository
git clone https://github.com/manishsongirkar/lighthouse-automation-suite.git
cd lighthouse-automation-suite

# Run enhanced automated setup (recommended)
chmod +x setup.sh
./setup.sh

# Validate setup (optional but recommended)
python validate_setup.py

# Add your URLs to analyze
echo "https://example.com" >> urls.txt

# Run the complete enhanced workflow (recommended)
python run_analysis.py

# View the results
# Dashboard opens automatically in browser

Your comprehensive dashboard will be ready in minutes! For detailed setup and customization options, see the full setup instructions below.

πŸ› οΈ Setup Instructions

Prerequisites

  • Python 3.7+
  • Google Chrome browser
  • Internet connection

Installation

Option 1: Enhanced Automated Setup (Recommended) πŸš€

# 1. Clone or download this project
git clone https://github.com/manishsongirkar/lighthouse-automation-suite.git
cd lighthouse-automation-suite

# 2. Run the enhanced automated setup script
chmod +x setup.sh
./setup.sh

# 3. Validate your setup (optional but recommended)
python validate_setup.py

The enhanced setup script will automatically:

  • βœ… Detect your operating system (macOS, Linux, Windows)
  • βœ… Check Python 3.7+ installation with version validation
  • βœ… Create virtual environment (.venv/) with cross-platform support
  • βœ… Install all required dependencies from requirements.txt
  • βœ… Create sample urls.txt file with examples and documentation
  • βœ… Verify Google Chrome installation across all platforms
  • βœ… Test all modules and ChromeDriver download capability
  • βœ… Provide comprehensive setup validation and next steps
  • βœ… Give platform-specific activation instructions

Option 2: Manual Setup

  1. Clone or download this project
git clone https://github.com/manishsongirkar/lighthouse-automation-suite.git
cd lighthouse-automation-suite
  1. Set up Python environment
python3 -m venv .venv
source .venv/bin/activate  # On Windows: .venv\\Scripts\\activate
  1. Install dependencies
pip install -r requirements.txt
  1. Configure URLs to test Edit urls.txt and add your URLs (one per line):
https://www.example.com
https://www.yoursite.com
https://www.competitor.com

πŸš€ Usage

Option 1: Run Complete Enhanced Workflow (Recommended)

python run_analysis.py

This runs the full enhanced workflow:

  • 🧹 Automatic cleanup of old report files
  • πŸ“Š Lighthouse analysis with comprehensive metrics
  • πŸ“Έ Optional Full HD screenshots of mobile and desktop views
  • 🎨 Enhanced tabbed dashboard generation
  • 🌐 Auto-opens the dashboard in your browser

πŸ“Έ Screenshot Capture

The tool now includes optional Full HD screenshot capture functionality:

Enable Screenshots: When running python run_analysis.py, you'll be prompted:

πŸ“Έ Enable Full HD full-page screenshot capture? (Y/n): Y

Screenshot Features:

  • βœ… Full HD Quality: 1920px width with complete page height
  • βœ… Mobile & Desktop Views: Captures both device perspectives
  • βœ… Automatic Organization: Timestamped directories (screenshots-YYYYMMDD_HHMMSS/)
  • βœ… Professional Quality: Ready for presentations and reports

Screenshot Files Generated:

screenshots-20251030_115303/
β”œβ”€β”€ fullhd_mobile_01_www.google.com.png      # Mobile view
β”œβ”€β”€ fullhd_desktop_01_www.google.com.png     # Desktop view
β”œβ”€β”€ fullhd_mobile_02_www.github.com.png      # Mobile view
└── fullhd_desktop_02_www.github.com.png     # Desktop view

Use Cases:

  • πŸ“Š Visual verification of performance scores
  • πŸ“ˆ Client presentations with high-quality screenshots
  • πŸ“‹ Documentation for before/after comparisons
  • 🎯 Quality assurance for automated analysis

Option 2: Generate HTML Dashboard

python generate_html_report.py

Creates the performance dashboard with optimization insights

Option 3: Run Individual Components

Lighthouse analysis only:

python main.py

HTML dashboard only (after analysis):

python generate_html_report.py

πŸ“Š Output Files

1. pagespeed_results.csv - Clean Main Data

  • Core performance metrics only - No cluttered internal fields
  • Excel/Google Sheets ready - Direct import without cleanup
  • Contains all scores and Core Web Vitals metrics
  • Backward compatible - Same format as before for existing workflows

2. pagespeed_report.html - Performance Dashboard

  • πŸ“Š Clean performance overview with Core Web Vitals matrix
  • Color-coded performance indicators with Google thresholds
  • Responsive design - Works perfectly on all devices
  • Professional styling focused on essential metrics

3. screenshots-YYYYMMDD_HHMMSS/ - Full HD Screenshots (Optional)

  • πŸ“± Mobile Screenshots: fullhd_mobile_XX_url.png - Full HD mobile view
  • πŸ–₯️ Desktop Screenshots: fullhd_desktop_XX_url.png - Full HD desktop view
  • Professional Quality: 1920px width with complete page capture
  • Organized Structure: Timestamped directories with safe filenames

4. Console Reports

  • Summary statistics with Core Web Vitals
  • Performance issue alerts with color indicators
  • Average scores across all URLs
  • Actionable recommendations

πŸ“ˆ Sample Output

$ python3 run_analysis.py
πŸš€ Lighthouse Automation Suite Workflow
==================================================
🧹 Cleaning up existing result files...
   ℹ️  pagespeed_results.csv does not exist (skip)
   ℹ️  pagespeed_report.html does not exist (skip)
βœ… Cleanup completed - no files to remove
βœ… Using virtual environment: .venv/bin/python
πŸ“Š URL Analysis Results:
   πŸ“„ Total lines in file: 2
   βœ… Valid URLs found: 2

πŸ“Έ Enable Full HD full-page screenshot capture? (Y/n): Y
πŸ“Έ Using optimized script with Full HD screenshot capture

πŸ”„ Optimized Lighthouse Analysis with Full HD Screenshots...
βœ… Successfully loaded 2 valid URLs from urls.txt
πŸ“Έ Screenshots will be saved to a timestamped directory
πŸš€ Starting Lighthouse analysis for 2 URLs...
============================================================
πŸ”„ Processing URL 1/2 (50.0%)
πŸ“Š Current URL: https://www.google.com
============================================================
πŸ”§ Chrome optimized: Headless mode, performance-focused settings
Navigating to: https://pagespeed.web.dev/analysis?url=https://www.google.com
⏳ Waiting for analysis to complete...
⚑ Waiting for Lighthouse JSON data (optimized timeout: 120s)...
βœ… Initial Lighthouse JSON data detected.
⚑ Waiting for both mobile and desktop data (optimized: 30s max)...
βœ… Both mobile and desktop JSON data are available!
οΏ½ Extracting available results...
οΏ½πŸ“ Created screenshot directory: screenshots-20251105_143022
πŸ“Έ Capturing Full HD screenshots for mobile and desktop...
πŸ“± Switched to mobile view
βœ… Full HD mobile screenshot saved: screenshots-20251105_143022/fullhd_mobile_01_www.google.com.png
πŸ–₯️ Switched to desktop view
βœ… Full HD desktop screenshot saved: screenshots-20251105_143022/fullhd_desktop_01_www.google.com.png
Final URL: https://pagespeed.web.dev/analysis
πŸ“± Extracting mobile scores and metrics...
πŸ’» Extracting desktop scores and metrics...

πŸ“Š Performance Metrics Summary
========================================================
Metric                     | πŸ“± Mobile     | πŸ–₯️  Desktop 
========================================================
Performance                | 89 ⚠️         | 100 βœ…       
Accessibility              | 95 βœ…         | 95 βœ…        
Best Practices             | 96 βœ…         | 96 βœ…        
SEO                        | 91 βœ…         | 92 βœ…        
First Contentful Paint     | 1.2 s        | 0.4 s       
Largest Contentful Paint   | 1.3 s        | 0.6 s       
Total Blocking Time        | 120 ms       | 0 ms        
Cumulative Layout Shift    | 0.000        | 0.000       
Speed Index                | 1.4 s        | 0.7 s       
Time to Interactive        | 1.7 s        | 0.8 s       
First Meaningful Paint     | 1.2 s        | 0.4 s       
========================================================

Results for https://www.google.com successfully written to pagespeed_results.csv
βœ… Successfully processed: https://www.google.com
⏳ Waiting 7 seconds before next test...
============================================================
πŸ”„ Processing URL 2/2 (100.0%)
πŸ“Š Current URL: https://www.github.com
============================================================
οΏ½ Chrome optimized: Headless mode, performance-focused settings
Navigating to: https://pagespeed.web.dev/analysis?url=https://www.github.com
⏳ Waiting for analysis to complete...
⚑ Waiting for Lighthouse JSON data (optimized timeout: 120s)...
βœ… Initial Lighthouse JSON data detected.
⚑ Waiting for both mobile and desktop data (optimized: 30s max)...
βœ… Both mobile and desktop JSON data are available!
πŸ” Extracting available results...
πŸ“Έ Capturing Full HD screenshots for mobile and desktop...
πŸ“± Switched to mobile view
βœ… Full HD mobile screenshot saved: screenshots-20251105_143022/fullhd_mobile_02_www.github.com.png
πŸ–₯️ Switched to desktop view
βœ… Full HD desktop screenshot saved: screenshots-20251105_143022/fullhd_desktop_02_www.github.com.png
Final URL: https://pagespeed.web.dev/analysis
πŸ“± Extracting mobile scores and metrics...
πŸ’» Extracting desktop scores and metrics...

πŸ“Š Performance Metrics Summary
========================================================
Metric                     | πŸ“± Mobile     | πŸ–₯️  Desktop 
========================================================
Performance                | 62 ⚠️         | 78 ⚠️        
Accessibility              | 83 ⚠️         | 83 ⚠️        
Best Practices             | 78 ⚠️         | 78 ⚠️        
SEO                        | 91 βœ…         | 92 βœ…        
First Contentful Paint     | 2.1 s        | 0.9 s       
Largest Contentful Paint   | 4.2 s        | 1.8 s       
Total Blocking Time        | 580 ms       | 280 ms      
Cumulative Layout Shift    | 0.095        | 0.042       
Speed Index                | 3.8 s        | 2.1 s       
Time to Interactive        | 4.9 s        | 2.3 s       
First Meaningful Paint     | 2.3 s        | 1.1 s       
========================================================

Results for https://www.github.com successfully written to pagespeed_results.csv
βœ… Successfully processed: https://www.github.com
Browser closed for URL: https://www.github.com

============================================================
πŸŽ‰ All tests completed!
πŸ“Š Generated files:
  β€’ pagespeed_results.csv - Core performance metrics and scores
  πŸ“Έ screenshots-20251105_143022/ - Screenshots (4 files)
    πŸ“± Mobile: 2 | πŸ–₯️  Desktop: 2
βœ… Optimized Lighthouse Analysis with Full HD Screenshots completed successfully

πŸ”„ HTML Dashboard Generation...
πŸ“Š Processing 2 unique URLs for enhanced HTML report
βœ… Enhanced HTML report generated: pagespeed_report.html
   Open in browser: file:///Users/john/Sites/pagespeed-insights-automation/pagespeed_report.html
βœ… HTML Dashboard Generation completed successfully

==================================================
πŸŽ‰ WORKFLOW COMPLETED SUCCESSFULLY!
==================================================

πŸ“‚ Generated Files:
   πŸ“Š pagespeed_results.csv     - Core performance metrics and scores
   🎯 pagespeed_report.html     - Performance dashboard
   πŸ“Έ screenshots-20251105_143022/     - Full HD Screenshots (4 files)
       πŸ“± Mobile: 2 | πŸ–₯️  Desktop: 2

🌐 Open HTML report in browser? (y/n): y
βœ… HTML report opened in browser

πŸ“‚ Open Full HD screenshot directory? (y/n): y
βœ… Screenshot directory opened: screenshots-20251105_143022

πŸ’‘ Next Steps:
   β€’ Review the performance dashboard for visual insights
   β€’ Import CSV data into Excel/Google Sheets for further analysis
   β€’ Check Full HD screenshot files for complete page verification
   β€’ Focus on URLs with Core Web Vitals issues
   β€’ Re-run analysis after implementing optimizations

βš™οΈ Configuration Options

Modify Delays

Edit main.py to adjust delays between requests:

delay = random.randint(5, 10)  # 5-10 second random delay

Change Output Filename

Modify the CSV filename in main.py:

write_to_csv(page_speed_scores, "custom_filename.csv")

Screenshot Settings

Enable/disable screenshots in the workflow:

# In run_analysis.py - interactive prompt
πŸ“Έ Enable Full HD full-page screenshot capture? (Y/n): Y

# Or pass directly to main.py
enable_screenshots = True  # Set to False to disable

Browser Configuration

The tool runs in optimized headless mode by default. To modify browser settings, edit main.py:

# Browser is automatically configured for optimal performance
# Headless mode is enabled by default for better performance
options.add_argument("--headless")  # Already enabled for optimization

πŸ”§ Troubleshooting

Common Issues

ChromeDriver Issues:

  • The tool auto-downloads ChromeDriver
  • Ensure Chrome browser is installed
  • Try updating Chrome to the latest version

Timeout Errors:

  • Increase timeout values in main.py
  • Check internet connection stability
  • Some websites may take longer to analyze

Rate Limiting:

  • Increase delays between requests
  • Use proxy rotation for large batches
  • Respect Google's terms of service

Missing Dependencies:

# Manual installation of all current dependencies
pip install selenium webdriver-manager fake-useragent pandas openpyxl

# Or re-run the automated setup script
./setup.sh

Screenshot Issues:

  • Ensure sufficient disk space for Full HD screenshots
  • Check write permissions in the project directory
  • Screenshots require successful Lighthouse analysis completion
  • If screenshots fail, analysis will continue normally

Setup Issues: If you encounter any setup problems, try the following steps:

  1. Run the enhanced setup script:
chmod +x setup.sh
./setup.sh
  1. Validate your setup:
python validate_setup.py

This will check all components and provide detailed diagnostics.

  1. Manual dependency installation:
# Activate virtual environment first
source .venv/bin/activate  # macOS/Linux
# or
.venv\Scripts\activate     # Windows

# Install/reinstall dependencies
pip install --force-reinstall -r requirements.txt

The validation script will identify specific issues and provide targeted solutions.

πŸ“‹ Best Practices

For Large URL Lists

  • Start with small batches (10-20 URLs)
  • Use longer delays (15-30 seconds) between requests
  • Run during off-peak hours to avoid rate limiting
  • Monitor for rate limiting and adjust delays accordingly
  • Consider disabling screenshots for very large batches to save time and space

For Screenshot Capture

  • Ensure adequate disk space (approximately 300-400 KB per URL)
  • Use screenshots for important analyses and client deliverables
  • Full HD screenshots are ideal for presentations and documentation
  • Screenshots can be disabled for routine monitoring to improve speed

For Accurate Results

  • Test the same URLs multiple times for consistency
  • Compare results across different time periods
  • Consider geographic location differences in CDN performance
  • Account for caching effects and server load variations

πŸ›‘οΈ Anti-Detection Features

  • Random user agents for each browser session
  • Disabled automation flags and detection bypassing
  • Navigator.webdriver property masking
  • Configurable request delays between URL processing
  • Optimized headless browser operation
  • Performance-focused Chrome settings to avoid detection

πŸ“ Project Structure

lighthouse-automation-suite/
β”œβ”€β”€ main.py                         # Core automation script with screenshot support
β”œβ”€β”€ urls.txt                        # URLs to analyze (supports comments)
β”œβ”€β”€ setup.sh                        # πŸš€ Automated setup script (recommended)
β”œβ”€β”€ generate_html_report.py          # πŸ“Š Performance dashboard generator
β”œβ”€β”€ run_analysis.py                 # πŸš€ Complete workflow runner (recommended)
β”œβ”€β”€ requirements.txt                # Python dependencies
β”œβ”€β”€ packages.txt                    # System dependencies
β”œβ”€β”€ README.md                       # Project documentation
β”œβ”€β”€ CORE_WEB_VITALS_UPDATE.md      # Latest feature updates (October 2025)
β”œβ”€β”€ .gitignore                      # Git ignore rules
β”œβ”€β”€ pagespeed_results.csv           # πŸ“Š Performance results (gitignored)
β”œβ”€β”€ pagespeed_report.html           # 🎨 Performance dashboard (gitignored)
└── screenshots-YYYYMMDD_HHMMSS/   # πŸ“Έ Full HD screenshots (gitignored)

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your improvements
  4. Test thoroughly
  5. Submit a pull request

πŸ“„ License

This project is open source. Use responsibly and respect Google's terms of service.

⚠️ Important Notes

  • This tool is for educational and legitimate business use only
  • Respect rate limits and terms of service
  • Consider the impact on PageSpeed Insights service
  • Use delays between requests to be respectful
  • Monitor your usage to avoid being blocked

πŸ†˜ Support

If you encounter issues:

  1. Check the troubleshooting section
  2. Verify all dependencies are installed
  3. Ensure URLs in urls.txt are valid
  4. Check internet connectivity
  5. Review console output for specific error messages

πŸ†• Latest Updates

October 30, 2025 - Full HD Screenshot Capture

  • βœ… πŸ“Έ Full HD Screenshot Support - Optional mobile and desktop screenshots
  • βœ… 🎯 Optimized Performance - 40% faster processing with reduced wait times
  • βœ… πŸ–₯️ Professional Quality - 1920px Full HD screenshots with complete page capture
  • βœ… πŸ“ Organized Output - Timestamped screenshot directories
  • βœ… πŸš€ Streamlined Integration - Single script with all functionality

October 16, 2025 - Enhanced Dashboard & Clean Data Structure

  • βœ… πŸ†• Tabbed interface with Performance Overview, Optimization Opportunities, and Accessibility Issues
  • βœ… 🧹 Clean CSV structure - Main CSV no longer contains internal fields
  • βœ… πŸ“‹ Separate detail files - Dedicated CSV files for optimization, accessibility, and SEO insights
  • βœ… 🎨 Enhanced UI/UX - Fixed tab hover states, 4-column grid layout, professional styling
  • βœ… πŸ“Š Core Web Vitals matrix - Detailed performance metrics in Performance Overview tab
  • βœ… πŸ”„ Backward compatibility - Existing pagespeed_results.csv workflows unchanged

October 2025 - Color-Coded Core Web Vitals

  • βœ… Color-coded HTML dashboard with Google performance thresholds
  • βœ… Green/Orange/Red indicators for instant performance identification
  • βœ… Professional styling with responsive design
  • βœ… Enhanced URL validation with detailed reporting
  • βœ… Cross-platform compatibility with dynamic paths

See CORE_WEB_VITALS_UPDATE.md for detailed information about all enhancements.


Happy Analyzing! πŸŽ‰

About

Automated Lighthouse performance analysis with Python. Batch URL testing, Core Web Vitals monitoring, Full HD screenshots & clean CSV/HTML reports.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published