Analyze HAR files and identify page-load bottlenecks
Project description
HAR Analyzer
A command-line tool that parses .har files and identifies page-load bottlenecks —
slow requests, large assets, missing cache headers, ad/tracker overload, and more.
Requirements
- Python 3.8+ (no third-party packages required — standard library only)
Quick Start
# Analyze a HAR file and print the report
python3 har-analyzer.py metrics/hars/mypage.har
# Save the report to metrics/reports/ as well
python3 har-analyzer.py metrics/hars/mypage.har --output metrics/reports/
How to Capture a HAR File
Chrome / Edge
- Open DevTools (
F12orCmd+Option+I) - Go to the Network tab
- Check Preserve log and Disable cache
- Navigate to the page you want to analyze
- Right-click the request list → Save all as HAR with content
- Save the file into
metrics/hars/
Firefox
- Open DevTools → Network tab
- Navigate to the page
- Click the gear icon → Save All As HAR
Safari
- Open Develop menu → Show Web Inspector
- Go to the Network tab
- Navigate to the page
- Click Export (floppy disk icon) to save the HAR
Sanitizing HAR Files Before Analysis
Important: HAR files captured from a browser contain session cookies, auth tokens, API keys, and personal data. Sanitize them before sharing, committing, or storing.
har-capture handles sanitization.
It requires no permanent installation — run it with uvx:
uvx "har-capture[cli]" <command>
Recommended workflow
capture in browser → validate → sanitize → analyze
1. Validate — check what's sensitive before touching it
# Check a single file
uvx "har-capture[cli]" validate metrics/hars/mypage.har
# Scan the whole hars/ folder (recursive)
uvx "har-capture[cli]" validate --dir metrics/hars/ --recursive
# Treat any warning as an error (useful in CI)
uvx "har-capture[cli]" validate metrics/hars/mypage.har --strict
The validator scans for passwords, tokens, API keys, MAC addresses, IP addresses, and other PII and exits non-zero if any are found.
2. Sanitize — redact PII and produce a clean file
# Basic — writes mypage.sanitized.har alongside the original
uvx "har-capture[cli]" sanitize metrics/hars/mypage.har
# Write to a specific path
uvx "har-capture[cli]" sanitize metrics/hars/mypage.har --output metrics/hars/mypage.clean.har
# Also produce a compressed .har.gz (useful for large captures)
uvx "har-capture[cli]" sanitize metrics/hars/mypage.har --compress
# Write a JSON report of everything that was redacted
uvx "har-capture[cli]" sanitize metrics/hars/mypage.har --report metrics/reports/redaction.json
# Skip the interactive review step (good for scripting)
uvx "har-capture[cli]" sanitize metrics/hars/mypage.har --no-interactive
How redaction works:
By default each sensitive value is replaced with a salted hash. The same value always
maps to the same hash within a session, so cross-request correlation is preserved while
the actual value is hidden. Pass --no-salt to use static [REDACTED] placeholders
instead.
3. Capture directly from a URL (auto-sanitizes)
har-capture get drives a headless browser and sanitizes the output in one step:
# Capture and auto-sanitize (writes <hostname>.har + <hostname>.har.gz)
uvx "har-capture[cli]" get https://example.com
# Save to a specific file
uvx "har-capture[cli]" get https://example.com --output metrics/hars/example.har
# Keep the raw (unsanitized) file alongside the sanitized one
uvx "har-capture[cli]" get https://example.com --keep-raw
# Include images and fonts in the capture (excluded by default)
uvx "har-capture[cli]" get https://example.com --include-images --include-fonts
# Use Firefox instead of the default Chromium
uvx "har-capture[cli]" get https://example.com --browser firefox
# Skip sanitization (not recommended for sharing)
uvx "har-capture[cli]" get https://example.com --no-sanitize
Full workflow example
# 1. Capture from URL into the metrics/hars folder
# (uses uv run so it finds Playwright browsers already installed on the system)
uv run --with "har-capture[cli]" --python python3 \
har-capture get https://www.example.com \
--output metrics/hars/example.har \
--include-images
# 2. Validate the sanitized file
uvx "har-capture[cli]" validate metrics/hars/example.har --strict
# 3. Analyze
python3 har-analyzer.py metrics/hars/example.har --output metrics/reports/
Or, for a HAR captured manually in the browser:
# 1. Sanitize the browser export
uvx "har-capture[cli]" sanitize metrics/hars/raw.har \
--output metrics/hars/raw.clean.har \
--report metrics/reports/redaction.json
# 2. Validate the result
uvx "har-capture[cli]" validate metrics/hars/raw.clean.har --strict
# 3. Analyze
python3 har-analyzer.py metrics/hars/raw.clean.har --output metrics/reports/
Output
The tool prints a report to stdout containing:
| Section | What it shows |
|---|---|
| Overview | DOMContentLoaded, onLoad, request count, total transfer size |
| Bottleneck Summary | Ranked list of CRITICAL / WARNING findings with fix recommendations |
| Top Slowest Requests | Time, TTFB, SSL, status, KB for the 15 slowest requests |
| Large Resources | Resources over 50 KB with type and cache headers |
| Content Type Breakdown | Total KB per MIME type |
| Top Domains | Request count, KB, and average time per origin |
| Slow TTFB | Requests with >300ms wait time |
| Slow TLS | Cold TLS handshakes >100ms |
| Slow DNS | DNS lookups >50ms |
| Poorly Cached Resources | Large resources missing Cache-Control |
| Redirects | All 3xx chains |
| HTTP Version Breakdown | HTTP/1.1 vs HTTP/2 usage |
| Concurrency | Peak concurrent requests in the first 5 seconds |
When --output is given, the report is also written to a timestamped file:
metrics/reports/<stem>_YYYYMMDD_HHMMSS.txt
All Options
python3 har-analyzer.py <har> [options]
Positional:
har Path to the .har file
Options:
--output, -o DIR Directory to write the text report
--large-kb N Threshold (KB) for "large resource" section (default: 50)
--ttfb-ms N Slow TTFB threshold in ms (default: 300)
--ssl-ms N Slow TLS threshold in ms (default: 100)
--dns-ms N Slow DNS threshold in ms (default: 50)
--top-n N Number of slowest requests to list (default: 15)
Folder Structure
webanalytics/
├── har-analyzer.py # main script
├── README.md # this file
├── developer.md # how to extend the tool
└── metrics/
├── hars/ # drop your .har files here
└── reports/ # generated reports land here
Examples
# Higher threshold — only flag resources over 200 KB
python3 har-analyzer.py metrics/hars/checkout.har --large-kb 200
# Show top 30 slowest requests
python3 har-analyzer.py metrics/hars/homepage.har --top-n 30
# Stricter TTFB — flag anything over 100ms
python3 har-analyzer.py metrics/hars/api-heavy.har --ttfb-ms 100 --output metrics/reports/
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dvm_haranalyzer-0.1.0.tar.gz.
File metadata
- Download URL: dvm_haranalyzer-0.1.0.tar.gz
- Upload date:
- Size: 10.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.2 {"installer":{"name":"uv","version":"0.10.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
13b3663f28a886b23587189a77768b0a371ec57aca89b6603560233a2a256795
|
|
| MD5 |
82bdec224323e8f361ba2da4db73149a
|
|
| BLAKE2b-256 |
173bcf5ad2520bf139915a17138379ba046ace67b5342a3b2eb44f950f4f87ed
|
File details
Details for the file dvm_haranalyzer-0.1.0-py3-none-any.whl.
File metadata
- Download URL: dvm_haranalyzer-0.1.0-py3-none-any.whl
- Upload date:
- Size: 10.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.2 {"installer":{"name":"uv","version":"0.10.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
442ac1be30e0715553139dc55d43afcd8a6e1c6a67ef5d861d15de4d1d048031
|
|
| MD5 |
76c10b16d376b356f3490ab12200b14f
|
|
| BLAKE2b-256 |
f6fa80c8964b642645843c39d62ff7148b0744344833b65b0b01599bd2e2555f
|