run_playwright.py is an interactive browser log capture tool that's part of the LogHawk platform. It opens a real browser window where you can interact with websites while automatically capturing:
- Console logs (info, warnings, errors, debug messages)
- Network requests (all HTTP requests/responses)
- JavaScript errors (runtime errors, stack traces)
- Network errors (failed requests, 4xx/5xx responses)
The captured logs are saved in structured formats (JSON + human-readable text) for analysis with LogHawk's filtering system.
pip install playwright asyncioInstall Playwright browsers (required first time):
python -m playwright install chromiumOr install all browsers:
python -m playwright install# Start interactive session with Google
python run_playwright.py
# Start with a specific website
python run_playwright.py --url "https://example.com"
# Run in background (no browser window)
python run_playwright.py --headless --url "https://api.example.com"
# Test mode (no files saved)
python run_playwright.py --dry-run --url "https://example.com"| Option | Description | Default |
|---|---|---|
--url |
Initial URL to navigate to | https://google.com |
--headless |
Run browser in background (no window) | False |
--log-dir |
Directory to save log files | browser_logs |
--dry-run |
Show statistics only, don't save files | False |
# E-commerce testing with custom log directory
python run_playwright.py --url "https://shop.example.com" --log-dir "ecommerce_logs"
# Background API testing
python run_playwright.py --headless --url "https://api.example.com/dashboard"
# Quick testing without saving files
python run_playwright.py --dry-run --url "https://new-feature.staging.com"
# Debug session with specific site
python run_playwright.py --url "https://localhost:3000" --log-dir "debug_session"python run_playwright.py --url "https://your-website.com"- The browser window opens automatically
- Navigate, click, fill forms, trigger JavaScript - everything is captured
- Console messages appear in real-time in your terminal
- All interactions are logged automatically
Press Ctrl+C when done - you'll be prompted:
[SAVE] Save captured logs? (y)es/(n)o/(d)ry-run stats:
Choose:
y- Save full logs to filesn- Show stats but don't saved- Show detailed statistics only
Files are saved to the browser_logs/ directory:
- JSON file:
browser_console_YYYYMMDD_HHMMSS.json(structured data) - TXT file:
browser_console_YYYYMMDD_HHMMSS.log(human-readable)
{
"session_info": {
"session_id": "20250801_143022",
"start_time": "2025-08-01T14:30:22",
"end_time": "2025-08-01T14:35:45",
"total_console_messages": 15,
"total_network_requests": 42,
"total_errors": 2
},
"console_logs": [...],
"network_requests": [...],
"errors": [...]
}# LogHawk Browser Console Capture
# Session: 20250801_143022
# Total messages: 15
# Captured: 2025-08-01 14:35:45
2025-08-01 14:30:23.123 [INFO] Page loaded successfully
2025-08-01 14:30:24.456 [ERROR] Failed to load resource: 404
...
# Debug React/Vue/Angular app
python run_playwright.py --url "http://localhost:3000"
# Test production deployment
python run_playwright.py --url "https://myapp.com" --log-dir "production_test"# Background testing of API calls
python run_playwright.py --headless --url "https://app.com/dashboard"# Test complete user flows
python run_playwright.py --url "https://shop.com/checkout" --log-dir "checkout_flow"# Fast testing without cluttering disk
python run_playwright.py --dry-run --url "https://staging.example.com"After capturing logs, analyze them with LogHawk:
# Start LogHawk server
python run_loghawk.py
# Open browser to: http://127.0.0.1:8765
# Set log path to: ./browser_logs
# Use filters to analyze captured data- User Interactions: Click, button, form, submit, navigation
- Frontend Issues: TypeError, Promise, CORS, Hook
- Network Problems: 404, 500, timeout, fetch
# Install browsers first
python -m playwright install chromium
# Or try headless mode
python run_playwright.py --headless- Make sure to interact with the website (click, navigate, etc.)
- Check browser console for JavaScript activity
- Try a site with more dynamic content
# Create logs directory manually
mkdir browser_logs
# Or use custom directory
python run_playwright.py --log-dir "my_logs"If you see character encoding errors, the script automatically uses ASCII-safe prefixes like [START], [ERROR] instead of emojis.
Fixed! Logs are now saved automatically even if:
- Browser crashes
- Process is killed
- Network disconnects
- System shuts down
The tool responds to system signals gracefully:
Ctrl+C- Normal shutdown with save promptSIGTERM- Graceful shutdown (saves automatically)
Even if the session ends unexpectedly, logs are preserved in the finally block.
python run_playwright.py --dry-runShows what would be captured without saving files:
[STATS] Session Statistics:
Console messages: 23
Network requests: 67
JavaScript errors: 1
Network errors: 3
Total errors: 4
The tool uses a realistic Chrome user agent to avoid bot detection.
# Use descriptive log directories
python run_playwright.py --log-dir "feature_x_testing" --url "https://app.com/feature-x"
# Date-based organization
python run_playwright.py --log-dir "logs_$(date +%Y%m%d)" --url "https://app.com"#!/bin/bash
# Test multiple environments
for env in dev staging prod; do
python run_playwright.py --headless --log-dir "${env}_logs" --url "https://${env}.myapp.com"
done# GitHub Actions example
- name: Capture Frontend Logs
run: |
timeout 60s python run_playwright.py --headless --dry-run --url "$DEPLOY_URL" || echo "Capture complete"- Capture: Use
run_playwright.pyto capture logs - Analyze: Use LogHawk server to filter and analyze
- Debug: Use LogHawk's smart filters to find issues
- Repeat: Iterate on fixes and re-test
This creates a powerful workflow for modern web development debugging.
- Check LogHawk documentation:
CLAUDE.md - Run with
--helpfor quick reference - Use
--dry-runfor testing without files - Start with simple sites like Google before complex applications