Playwright Trace Viewer Not Opening Fix
In this tutorial, you'll learn about Playwright Trace Viewer Not Opening Fix. We cover key concepts, practical examples, and best practices.
Your Playwright trace files aren't generated — or the trace viewer doesn't open when you try to view them.
The Problem
// WRONG — trace not configured
import { test } from '@playwright/test';
test('login flow', async ({ page }) => {
// No trace recorded — nothing to debug with
});
No trace files exist, so you can't use the trace viewer to debug failures.
Step-by-Step Fix
1. Enable tracing in config
// RIGHT — playwright.config.ts
import { defineConfig } from '@playwright/test';
export default defineConfig({
use: {
trace: 'retain-on-failure',
},
});
2. Choose trace mode
// RIGHT — trace modes
export default defineConfig({
use: {
// 'off' — no trace (default)
// 'on' — trace all tests
// 'retain-on-failure' — trace, keep only on failure
// 'on-first-retry' — trace on first retry
// 'on-all-retries' — trace on all retries
trace: 'on',
},
});
3. Enable trace per test
// RIGHT — per-test tracing
import { test } from '@playwright/test';
test.use({ trace: 'on' });
test('debug this test', async ({ page, trace }) => {
await page.goto('https://example.com');
// Full trace recorded for this test
});
4. View traces
# RIGHT — open trace viewer
npx playwright show-trace path/to/trace.zip
# Or open the HTML report
npx playwright show-report
5. Programmatic trace control
// RIGHT — manual trace start/stop
test('manual trace', async ({ page, context }) => {
await context.tracing.start({ screenshots: true, snapshots: true });
await page.goto('https://example.com');
await page.click('button');
await context.tracing.stop({ path: 'trace.zip' });
});
Expected output:
✓ login flow (1.2s) [trace attached]
View trace: npx playwright show-trace test-results/login-flow/trace.zip
Prevention Tips
- Enable
trace: 'retain-on-failure'in config - Use
trace: 'on'for specific tests you're debugging - Open traces with
npx <a href="/testing-qa/playwright/">playwright</a> show-trace - Use the trace viewer to inspect DOM snapshots and network logs
- Set
screenshots: trueandsnapshots: truefor full detail
Common Mistakes with trace viewer
- Non-exhaustive pattern matches that compile with warnings then crash at runtime
- Misunderstanding that
Stringis[Char]with poor performance for large text operations - Using
foldlinstead offoldl'causing stack overflow on large lists
These mistakes appear frequently in real-world PLAYWRIGHT code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.
Practice Exercise
Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.
This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.
FAQ
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro