|
| 1 | +<!doctype html> |
| 2 | +<html lang="en"> |
| 3 | +<head> |
| 4 | + <meta charset="utf-8"> |
| 5 | + <meta name="viewport" content="width=device-width, initial-scale=1"> |
| 6 | + <meta name="description" content="Debug Playwright scripts that use LLM decisions with local screenshots, URLs, model I/O, errors, and shareable BrowserTrace exports."> |
| 7 | + <meta property="og:title" content="Debug Playwright + LLM browser-agent failures with BrowserTrace"> |
| 8 | + <meta property="og:description" content="Record Playwright screenshots and LLM decisions in one local timeline."> |
| 9 | + <meta property="og:image" content="https://aaronlab.github.io/browsertrace/social-preview.png"> |
| 10 | + <meta property="og:type" content="article"> |
| 11 | + <meta name="twitter:card" content="summary_large_image"> |
| 12 | + <link rel="canonical" href="https://aaronlab.github.io/browsertrace/playwright-llm-debugging.html"> |
| 13 | + <title>Debug Playwright + LLM Browser-Agent Failures with BrowserTrace</title> |
| 14 | + <style> |
| 15 | + :root { |
| 16 | + color-scheme: light; |
| 17 | + --ink: #172026; |
| 18 | + --muted: #5f6b76; |
| 19 | + --line: #d9e1e7; |
| 20 | + --paper: #f7f9fb; |
| 21 | + --panel: #ffffff; |
| 22 | + --accent: #0f766e; |
| 23 | + --code: #102026; |
| 24 | + } |
| 25 | + |
| 26 | + * { |
| 27 | + box-sizing: border-box; |
| 28 | + } |
| 29 | + |
| 30 | + body { |
| 31 | + margin: 0; |
| 32 | + background: var(--paper); |
| 33 | + color: var(--ink); |
| 34 | + font: 16px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; |
| 35 | + } |
| 36 | + |
| 37 | + a { |
| 38 | + color: #0369a1; |
| 39 | + text-decoration-thickness: 1px; |
| 40 | + text-underline-offset: 3px; |
| 41 | + } |
| 42 | + |
| 43 | + header { |
| 44 | + background: var(--panel); |
| 45 | + border-bottom: 1px solid var(--line); |
| 46 | + } |
| 47 | + |
| 48 | + .topbar, |
| 49 | + main, |
| 50 | + footer { |
| 51 | + width: min(960px, calc(100% - 32px)); |
| 52 | + margin: 0 auto; |
| 53 | + } |
| 54 | + |
| 55 | + .topbar { |
| 56 | + display: flex; |
| 57 | + align-items: center; |
| 58 | + justify-content: space-between; |
| 59 | + gap: 16px; |
| 60 | + flex-wrap: wrap; |
| 61 | + padding: 14px 0; |
| 62 | + } |
| 63 | + |
| 64 | + .brand { |
| 65 | + font-weight: 700; |
| 66 | + letter-spacing: 0; |
| 67 | + } |
| 68 | + |
| 69 | + nav { |
| 70 | + display: flex; |
| 71 | + gap: 14px; |
| 72 | + flex-wrap: wrap; |
| 73 | + font-size: 14px; |
| 74 | + } |
| 75 | + |
| 76 | + main { |
| 77 | + padding: 36px 0 54px; |
| 78 | + } |
| 79 | + |
| 80 | + h1 { |
| 81 | + margin: 0; |
| 82 | + max-width: 840px; |
| 83 | + font-size: clamp(34px, 5vw, 58px); |
| 84 | + line-height: 1.04; |
| 85 | + letter-spacing: 0; |
| 86 | + } |
| 87 | + |
| 88 | + .dek { |
| 89 | + max-width: 780px; |
| 90 | + margin: 18px 0 24px; |
| 91 | + color: var(--muted); |
| 92 | + font-size: 20px; |
| 93 | + line-height: 1.45; |
| 94 | + } |
| 95 | + |
| 96 | + .actions { |
| 97 | + display: flex; |
| 98 | + gap: 10px; |
| 99 | + flex-wrap: wrap; |
| 100 | + margin: 22px 0 6px; |
| 101 | + } |
| 102 | + |
| 103 | + .button { |
| 104 | + display: inline-flex; |
| 105 | + align-items: center; |
| 106 | + justify-content: center; |
| 107 | + min-height: 40px; |
| 108 | + padding: 0 14px; |
| 109 | + border: 1px solid var(--line); |
| 110 | + border-radius: 8px; |
| 111 | + background: var(--panel); |
| 112 | + color: var(--ink); |
| 113 | + font-weight: 600; |
| 114 | + text-decoration: none; |
| 115 | + white-space: nowrap; |
| 116 | + } |
| 117 | + |
| 118 | + .button.primary { |
| 119 | + border-color: var(--accent); |
| 120 | + background: var(--accent); |
| 121 | + color: #ffffff; |
| 122 | + } |
| 123 | + |
| 124 | + section { |
| 125 | + border-top: 1px solid var(--line); |
| 126 | + padding-top: 28px; |
| 127 | + margin-top: 30px; |
| 128 | + } |
| 129 | + |
| 130 | + h2 { |
| 131 | + margin: 0 0 10px; |
| 132 | + font-size: 24px; |
| 133 | + line-height: 1.2; |
| 134 | + letter-spacing: 0; |
| 135 | + } |
| 136 | + |
| 137 | + p, |
| 138 | + li { |
| 139 | + max-width: 780px; |
| 140 | + } |
| 141 | + |
| 142 | + ul, |
| 143 | + ol { |
| 144 | + padding-left: 24px; |
| 145 | + } |
| 146 | + |
| 147 | + pre { |
| 148 | + max-width: 880px; |
| 149 | + margin: 14px 0 0; |
| 150 | + padding: 16px; |
| 151 | + overflow: auto; |
| 152 | + border-radius: 8px; |
| 153 | + background: var(--code); |
| 154 | + color: #eef7f6; |
| 155 | + font: 13px/1.55 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; |
| 156 | + white-space: pre-wrap; |
| 157 | + } |
| 158 | + |
| 159 | + code { |
| 160 | + background: #eef3f6; |
| 161 | + border-radius: 4px; |
| 162 | + padding: 2px 5px; |
| 163 | + font-size: 0.92em; |
| 164 | + } |
| 165 | + |
| 166 | + pre code { |
| 167 | + padding: 0; |
| 168 | + background: transparent; |
| 169 | + } |
| 170 | + |
| 171 | + .note { |
| 172 | + max-width: 820px; |
| 173 | + border-left: 4px solid var(--accent); |
| 174 | + background: var(--panel); |
| 175 | + border-radius: 0 8px 8px 0; |
| 176 | + padding: 14px 16px; |
| 177 | + } |
| 178 | + |
| 179 | + footer { |
| 180 | + border-top: 1px solid var(--line); |
| 181 | + padding: 18px 0 34px; |
| 182 | + color: var(--muted); |
| 183 | + } |
| 184 | + </style> |
| 185 | +</head> |
| 186 | +<body> |
| 187 | + <header> |
| 188 | + <div class="topbar"> |
| 189 | + <div class="brand">BrowserTrace</div> |
| 190 | + <nav aria-label="Primary"> |
| 191 | + <a href="./">Live demo</a> |
| 192 | + <a href="./integrations.html">Integrations</a> |
| 193 | + <a href="./debug-browser-agent-failure.html">Walkthrough</a> |
| 194 | + <a href="https://github.com/aaronlab/browsertrace">GitHub</a> |
| 195 | + </nav> |
| 196 | + </div> |
| 197 | + </header> |
| 198 | + |
| 199 | + <main> |
| 200 | + <h1>Debug Playwright scripts where an LLM chooses the next browser action</h1> |
| 201 | + <p class="dek">Playwright Trace Viewer is strong for browser automation. BrowserTrace is for the extra failure context in LLM-guided browser runs: the prompt, model output, action label, screenshot, URL, status, and first error in one local timeline.</p> |
| 202 | + <div class="actions" aria-label="Primary actions"> |
| 203 | + <a class="button primary" href="https://github.com/aaronlab/browsertrace">View repo</a> |
| 204 | + <a class="button" href="./trace.html">Open exported trace</a> |
| 205 | + <a class="button" href="./integrations.html#playwright">Integration snippet</a> |
| 206 | + </div> |
| 207 | + |
| 208 | + <section> |
| 209 | + <h2>Try the local demo first</h2> |
| 210 | + <pre><code>pip install "browsertrace[ui] @ git+https://github.com/aaronlab/browsertrace@v0.1.6" |
| 211 | +browsertrace demo |
| 212 | +browsertrace</code></pre> |
| 213 | + <p>Open <code>http://127.0.0.1:3000</code> and inspect the failed checkout-agent run before adding BrowserTrace to your own Playwright script.</p> |
| 214 | + </section> |
| 215 | + |
| 216 | + <section> |
| 217 | + <h2>Capture the LLM decision points</h2> |
| 218 | + <pre><code>from browsertrace import Tracer |
| 219 | + |
| 220 | +tracer = Tracer() |
| 221 | + |
| 222 | +async with tracer.run("playwright llm agent") as run: |
| 223 | + await page.goto("https://example.com") |
| 224 | + await run.snapshot(page, action="opened example.com") |
| 225 | + |
| 226 | + prompt = "Choose the selector for the checkout button" |
| 227 | + decision = await llm_choose_next_action(prompt, page) |
| 228 | + |
| 229 | + await page.click(decision["selector"]) |
| 230 | + await run.snapshot( |
| 231 | + page, |
| 232 | + action="clicked model-selected element", |
| 233 | + model_input=prompt, |
| 234 | + model_output=decision, |
| 235 | + )</code></pre> |
| 236 | + <p>Snapshots pull the current Playwright URL and screenshot, then attach the model input and model output you pass in.</p> |
| 237 | + </section> |
| 238 | + |
| 239 | + <section> |
| 240 | + <h2>What this adds to Playwright traces</h2> |
| 241 | + <ul> |
| 242 | + <li>The LLM prompt or messages that caused the browser action.</li> |
| 243 | + <li>The model response, selected selector, or structured action plan.</li> |
| 244 | + <li>The screenshot and URL at the moment the decision was made.</li> |
| 245 | + <li>A browser-agent-first timeline that marks the first failed step.</li> |
| 246 | + <li>A standalone HTML export for issues, pull requests, and team review.</li> |
| 247 | + </ul> |
| 248 | + </section> |
| 249 | + |
| 250 | + <section> |
| 251 | + <h2>Share only what is safe</h2> |
| 252 | + <pre><code>browsertrace list |
| 253 | +browsertrace export <run_id> -o full.html |
| 254 | +browsertrace export <run_id> --redact -o public.html</code></pre> |
| 255 | + <p>Use <code>--redact</code> before attaching a real trace to a public issue or community thread.</p> |
| 256 | + </section> |
| 257 | + |
| 258 | + <section> |
| 259 | + <div class="note"> |
| 260 | + BrowserTrace is not a replacement for Playwright Trace Viewer. It is a local layer for Playwright scripts where LLM decisions are part of the bug. |
| 261 | + </div> |
| 262 | + </section> |
| 263 | + </main> |
| 264 | + |
| 265 | + <footer> |
| 266 | + <p>Repo: <a href="https://github.com/aaronlab/browsertrace">github.com/aaronlab/browsertrace</a></p> |
| 267 | + </footer> |
| 268 | +</body> |
| 269 | +</html> |
0 commit comments