Skip to content

Commit 08dcace

Browse files
authored
docs: standardize Playwright MCP headed/headless runbook across AI CLI harnesses (#1438)
1 parent adfd78d commit 08dcace

5 files changed

Lines changed: 141 additions & 1 deletion

File tree

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Playwright MCP Headed vs Headless Cheat Sheet
2+
3+
Quick operational reference for AI-first CLI sessions.
4+
5+
## 60-Second Triage
6+
7+
1. Decide task mode:
8+
- Login/demo/visual verification -> `headed`
9+
- CI/batch/non-interactive -> `headless`
10+
2. Check harness MCP config (not only shell env).
11+
3. If `headed` on Linux, verify display prerequisites are present.
12+
4. Restart harness session after config/env changes.
13+
5. Validate with a minimal post-login authenticated-page check.
14+
15+
## Decision Table
16+
17+
| Situation | Mode |
18+
|-----------|------|
19+
| Login/MFA needed | Headed |
20+
| Live demo or walkthrough | Headed |
21+
| Visual bug investigation | Headed |
22+
| CI or nightly automation | Headless |
23+
| Fast non-interactive extraction | Headless |
24+
25+
## Top Failure Signatures
26+
27+
1. Missing display/X server launch errors
28+
2. Browser does not appear despite headed intent
29+
3. Transport/session closed unexpectedly
30+
4. Login redirect succeeds but auth state is missing
31+
5. Works once, fails after restart
32+
33+
## Fix Direction (One Line Each)
34+
35+
- Display/X errors -> Ensure headed prerequisites are passed in harness MCP env.
36+
- No browser window -> Confirm harness is actually launching in headed mode.
37+
- Transport closed -> Restart harness and re-launch MCP with validated config.
38+
- Missing auth state -> Verify with authenticated route check after login.
39+
- Restart regression -> Persist config in harness file, not temporary shell only.
40+
41+
## Canonical Runbook
42+
43+
Use full procedure for detailed diagnostics and recovery:
44+
- `../knowledge/procedures/playwright-headed-vs-headless.md`
45+

knowledge/ai-index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ Your starting point for understanding and working with this dotfiles repository.
3434
### Debug or Fix Issues
3535
- Use [MCP Protocol Smoke Test](procedures/mcp-protocol-smoke-test.md) for MCP issues
3636
- Follow [MCP Error Reporting](procedures/mcp-error-reporting.md) when MCP tools fail
37+
- Use [Playwright Headed vs Headless](procedures/playwright-headed-vs-headless.md) for deterministic browser mode behavior
3738
- Apply [Systems Stewardship](principles/systems-stewardship.md) - Document fixes
3839

3940
### Improve Documentation
@@ -53,6 +54,7 @@ Your starting point for understanding and working with this dotfiles repository.
5354

5455
### When MCP Tools Don't Work
5556
- Follow [MCP Error Reporting](procedures/mcp-error-reporting.md) - We control these servers, we'll fix them!
57+
- Use [Playwright Headed vs Headless](procedures/playwright-headed-vs-headless.md) for browser mode triage and recovery
5658
- Creates self-healing systems through proper issue tracking
5759
- Remember: 80% core work, 20% documenting issues
5860

knowledge/procedures/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ This is THE workflow. Everything else supports this core process.
3232
- `mcp-tool-logging.md` - MCP server tool-level logging
3333
- `mcp-protocol-smoke-test.md` - Testing MCP protocol directly
3434
- `mcp-prompts.md` - Adding prompts to MCP servers
35+
- `playwright-headed-vs-headless.md` - Deterministic mode selection and recovery for AI CLI sessions
3536

3637
### Tips & Setup
3738
- `claude-code-tips.md` - Tips and shortcuts for Claude Code
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# Playwright MCP: Headed vs Headless
2+
3+
Cross-harness runbook for deterministic browser mode selection in AI-first CLI workflows.
4+
5+
## Why This Exists
6+
7+
In CLI harnesses, Playwright MCP mode can appear to "mysteriously" switch to headless because:
8+
- Harness-level config differs from shell-level env.
9+
- MCP subprocesses inherit only what the harness passes.
10+
- Display stack prerequisites are missing even when config requests headed mode.
11+
12+
This runbook makes headed and headless behavior predictable across:
13+
- Claude Code
14+
- OpenAI Codex
15+
- GitHub Copilot CLI
16+
17+
## Mode Selection
18+
19+
Choose `headed` when you need:
20+
- Login and MFA flows.
21+
- Live demos and walkthroughs.
22+
- Visual verification of UI states.
23+
- Debugging anti-bot/captcha interactions.
24+
25+
Choose `headless` when you need:
26+
- CI or batch automation.
27+
- Non-interactive extraction or checks.
28+
- Faster, repeatable automation without UI.
29+
30+
## Common Failure Signatures
31+
32+
- Launch error about missing X server or `$DISPLAY`.
33+
- Session dies with transport-closed style errors.
34+
- Login appears successful but follow-up page is unauthenticated.
35+
- Browser window never appears despite headed intent.
36+
37+
## Deterministic Diagnostics
38+
39+
Run this sequence in order:
40+
41+
1. Verify harness config source of truth.
42+
- Confirm the active config file for your harness and session.
43+
2. Verify MCP subprocess environment.
44+
- Ensure headed prerequisites are passed in harness config env, not only in shell.
45+
3. Verify display stack prerequisites.
46+
- Linux/X11: `DISPLAY` and `XAUTHORITY` must be valid for the session user.
47+
- Wayland environments may require Xwayland compatibility for specific setups.
48+
4. Verify restart boundary.
49+
- If config changed, restart the harness session so MCP launches with new env.
50+
5. Verify with a neutral authenticated-page check.
51+
- Confirm post-login access to a known authenticated route/view, not just a login redirect.
52+
53+
## Cross-Harness Notes
54+
55+
### Claude Code
56+
- Keep MCP server config aligned with `mcp/mcp.json` and enabled server settings.
57+
- If MCP env changes, restart the CLI session to relaunch subprocesses.
58+
59+
### OpenAI Codex
60+
- Configure Playwright MCP env under `.codex/config.toml` `[mcp_servers.playwright]`.
61+
- Treat shell exports as insufficient unless reflected in Codex MCP server env.
62+
63+
### GitHub Copilot CLI
64+
- Use the CLI's MCP config/env mechanism as the runtime source of truth.
65+
- Ensure session restarts occur after env/config updates.
66+
67+
## Recovery Playbook
68+
69+
Use smallest-safe-change-first:
70+
71+
1. Confirm intended mode for task (`headed` or `headless`).
72+
2. Align harness MCP env to that mode.
73+
3. Restart harness session.
74+
4. Re-run minimal navigation check.
75+
5. Re-run login or demo flow.
76+
6. Validate with an authenticated-page check.
77+
78+
Stop and escalate when:
79+
- Same failure repeats after two config-correct restarts.
80+
- Mode appears correct but auth state is unstable across immediate retries.
81+
82+
## Definition Of Done
83+
84+
- Intended mode is explicitly confirmed by behavior.
85+
- Target flow completes in that mode.
86+
- Follow-up authenticated-page verification passes.
87+
- Behavior remains stable after one full harness restart.
88+

mcp/README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ Wrapper scripts and configuration for MCP clients (Claude Code, Amazon Q, Cursor
3737

3838
When an MCP server shows as "failed" in Claude Code:
3939

40+
For browser mode selection and stability in AI CLI sessions, use:
41+
- `knowledge/procedures/playwright-headed-vs-headless.md`
42+
- `docs/playwright-headed-headless-cheatsheet.md`
43+
4044
### 1. Quick Health Check
4145
```bash
4246
# Check individual server logs if needed
@@ -91,4 +95,4 @@ check-mcp-logs --follow # Real-time logs
9195
```bash
9296
# Test MCP handshake for npm-based servers
9397
echo '{"jsonrpc": "2.0", "id": 1, "method": "initialize", "params": {"protocolVersion": "2024-11-05", "capabilities": {}, "clientInfo": {"name": "smoke-test", "version": "1.0.0"}}}' | npx @playwright/mcp
94-
```
98+
```

0 commit comments

Comments
 (0)