Playwright¶
A transparent wrapper for Playwright that automatically collects comprehensive performance metrics during web automation testing.
Note
The integrations the team actively uses and supports are listed on the front page: Kafka, HTTP and InfluxDB. Playwright is not currently one of them, but it remains available, documented, and open to contributions — if you rely on it or want to improve it, it’s a good candidate.
Overview¶
mite_playwright provides seamless integration with Playwright, automatically capturing detailed performance metrics including DNS timing, TCP/TLS handshake times, paint events, and browser performance data without requiring any changes to your existing Playwright code.
Features¶
Zero Code Changes - Works with existing Playwright scripts
Comprehensive Metrics - Network timing, paint events, page load metrics
Transparent Proxy - Intercepts all Playwright operations automatically
Navigation Focused - Captures metrics for page navigation operations
Performance Optimized - Minimal overhead on test execution
Error Handling - Automatic error tracking and reporting
Quick start¶
Installation¶
pip install playwright
playwright install
Basic Usage¶
from mite_playwright import mite_playwright
@mite_playwright
async def simple_test(ctx, playwright):
"""Simple navigation test with automatic metrics"""
browser = await playwright.chromium.launch()
page = await browser.new_page()
# Metrics automatically collected on navigation
await page.goto("https://example.com")
await browser.close()
Mock Context for Testing¶
class MockContext:
def __init__(self):
self.config = {}
def send(self, metric_name, **kwargs):
print(f"METRIC: {metric_name}")
for key, value in kwargs.items():
if isinstance(value, float):
print(f" {key}: {value:.4f}")
else:
print(f" {key}: {value}")
# Run your test
ctx = MockContext()
asyncio.run(simple_test(ctx))
Collected Metrics¶
Network Timing Metrics¶
Metric |
Description |
Unit |
|---|---|---|
|
DNS resolution time |
seconds |
|
TCP connection establishment |
seconds |
|
TLS handshake time (HTTPS only) |
seconds |
|
Time until first response byte |
seconds |
|
Time until response complete |
seconds |
|
Complete request duration |
seconds |
Response Metrics¶
Metric |
Description |
|---|---|
|
Requested URL |
|
HTTP status code |
|
Content-Length in bytes |
|
Request start timestamp |
|
Response start timestamp |
|
Response end timestamp |
Paint & Performance Metrics¶
Metric |
Description |
Unit |
|---|---|---|
|
First paint event |
seconds |
|
First contentful paint |
seconds |
|
JavaScript onload complete |
seconds |
|
Page render time |
seconds |
|
Time to interactive |
seconds |
|
Total page size including resources |
bytes |
Error Tracking¶
The wrapper automatically captures and reports errors for:
Navigation failures
Timeout errors
Element not found errors
Any Playwright exceptions
These are sent as playwright_error, with the method name and error details.
File Structure¶
mite_playwright/
├── __init__.py # Main wrapper implementation
├── mite_playwright_example.py # Usage examples
├── stats.py # Statistics utilities
└── README.md # Short pointer to this page
Troubleshooting¶
Common Issues¶
No metrics collected:
Ensure you’re using navigation methods (
goto,reload, etc.)Check that responses have valid timing data
Verify your context implements the
send()method
Import errors:
Install Playwright:
pip install playwrightInstall browsers:
playwright install