Browser Management for Testing
This project includes advanced test scripts that automatically check, update, and manage browsers before running tests, with robust timeout handling and permission-aware operations.
New NPM Scripts
Browser Management
-
npm run browsers:check
- Check if all browsers are installed and working -
npm run browsers:update
- Update browsers and verify installation -
npm run browsers:fix
- Force reinstall browsers and system dependencies -
npm run browsers:ensure-safe
- Safe browser setup with permission checks
Enhanced Test Scripts
All test scripts now include the --ensure-browsers
flag by default with smart timeout and permission handling:
-
npm run test:e2e
- End-to-end tests with automatic browser management -
npm run test:a11y
- Accessibility tests with automatic browser management -
npm run test:e2e:headed
- Headed tests with automatic browser management -
npm run test:e2e:debug
- Debug tests with automatic browser management -
npm run test:e2e:webkit
- WebKit-specific tests with automatic browser management
Enhanced Features
🔐 Permission-Aware Operations
- Write Permission Checking: Automatically detects if the user has sufficient permissions
- Graceful Bypass: Skips installation if no permissions and uses existing browsers
-
Safe Mode:
--skip-if-no-permissions
flag for restricted environments
⏰ Timeout Protection
- Browser Installation Timeout: 5 minutes maximum (configurable)
- System Dependencies Timeout: 3 minutes maximum (configurable)
- Browser Testing Timeout: 15 seconds per browser (configurable)
- Graceful Recovery: Continues with existing browsers if timeouts occur
🛡️ Robust Error Handling
- Process Management: Proper cleanup of hanging processes
- Bypass on Failure: Uses existing browsers if installation fails
- Clear Error Messages: Specific troubleshooting guidance
- Multiple Fallback Options: Several recovery strategies
Advanced Options
Command Line Flags
Environment-Specific Usage
How It Works
1. Permission Detection
- Checks write access to node_modules directory
- Verifies browser installation locations
- Adapts behavior based on available permissions
2. Smart Installation Strategy
- Check Existing: First verifies if browsers already work
- Install Only If Needed: Skips unnecessary downloads
- Timeout Protection: Prevents hanging installations
- Fallback Strategy: Uses existing browsers if installation fails
3. Multi-Level Recovery
- Primary: Install/update browsers normally
- Secondary: Skip system deps if they fail
- Tertiary: Use existing browsers if installation fails
- Final: Provide clear troubleshooting guidance
Troubleshooting
Permission Issues
Timeout Issues
Installation Failures
Error Messages and Solutions
Error Message | Solution |
---|---|
“Insufficient permissions detected” | Use npm run browsers:ensure-safe
|
“Browser installation timed out” | Use --skip-system-deps or check network |
“No working browsers found” | Try npm run browsers:fix
|
“System dependencies failed” | Normal in restricted environments, tests may still work |
Performance Features
- Skip Redundant Operations: Only installs if browsers aren’t working
- Parallel Verification: Tests all browsers simultaneously
- Smart Caching: Leverages Playwright’s built-in caching
- Quick Status Checks: Fast browser verification without installation
Security Features
- Permission Validation: Checks before attempting installations
- Process Isolation: Proper cleanup of child processes
- Timeout Protection: Prevents resource exhaustion
- Safe Defaults: Conservative settings for production environments
Technical Details
The browser management system consists of:
-
scripts/check-browsers.js
- Browser status verification with timeout handling -
scripts/ensure-browsers.js
- Smart installer with permission awareness -
scripts/test-runner.js
- Enhanced test runner with automatic browser management -
scripts/test-webkit.js
- WebKit-specific handling with fallbacks
Configuration Constants
Permission Checking
- Validates write access to installation directories
- Detects WSL/Linux permission restrictions
- Provides fallback strategies for limited environments
Timeout Handling
- Process-level timeouts with proper cleanup
- Graceful degradation on timeout
- Clear timeout notifications with next steps