# AgentScrub Visual session replay for [Browser Use](https://github.com/browser-use/browser-use) agent runs. When a browser automation agent silently does the wrong thing, the evidence is buried in a flat log. AgentScrub loads a completed run's history export and turns it into a scrubbable timeline: drag across the run like a video and watch, at every step, the screenshot the agent saw, the action it took, and the reasoning it stated — side by side. The question "where did this agent's reasoning break" becomes answerable in seconds. **Live:** https://agentscrub.vercel.app — opens on a landing page explaining the problem and mechanism; "Try it with a sample run" goes straight into the replay tool with no signup or install. ## Real LLM run: not yet done, and here's exactly why Everything in this repo has been tested against a file **written by browser-use's own serializer** (see below), but no run has been driven by an actual LLM end to end — no API key was available at build time. The plan, not yet executed: point browser-use's `ChatOpenAI` wrapper at OpenRouter's OpenAI-compatible endpoint (`base_url="https://openrouter.ai/api/v1"`) using a free-tier model, run a real multi-step task, and replace the sample with that genuine export. If you're reading this and it's still marked "not yet done," it means exactly that — ask before assuming otherwise. ## Features - **Timeline scrubber** — drag the slider (or use arrow keys / space to autoplay) and the screenshot, action, and reasoning update live for that step. Step tick marks are colored by status: neutral (ok), green (finished successfully), red (error / failed). - **Step detail panel** — full `thinking`, `evaluation_previous_goal`, `next_goal`, and `memory` text from the model output; every action with its exact parameters; the action's target element (tag, id, accessible name, XPath); every result including errors and extracted content. - **Element highlight** — when the export contains `interacted_element` bounds, the targeted element is outlined directly on the screenshot. - **Jump-to-failure** — if any step carries an error (or a `done` with `success: false`), one click jumps to the last failing step. - **Frame diff** — toggle Diff (or press `d`) to see a pixel diff of the previous frame vs the current one: unchanged pixels are dimmed, changed pixels glow magenta, so the actual effect of the agent's action is visually obvious. - **Import** — file picker, drag-and-drop, or paste. Entirely client-side: the file is parsed in your browser and never uploaded anywhere. ## The data format (and how it was verified) AgentScrub parses the JSON written by browser-use's `AgentHistoryList.save_to_file()` (what you get from `agent.save_history(...)`). The format was verified against **browser-use v0.13.7** — not guessed from docs: - Field structure read from the source of truth, [`browser_use/agent/views.py`](https://github.com/browser-use/browser-use/blob/main/browser_use/agent/views.py) (`AgentHistoryList`, `AgentHistory`, `AgentOutput`, `ActionResult`, `StepMetadata`, `BrowserStateHistory`). - The bundled sample file was **serialized by the library itself** (`tools/build_sample.py` constructs the history through browser-use's own Pydantic classes and its real action registry, calls `save_to_file()`, then round-trips it back through `AgentHistoryList.load_from_file()` as an assertion). What a step looks like (v0.13.7): ```jsonc { "model_output": { // null if the model produced no parsed output "thinking": "...", "evaluation_previous_goal": "...", "memory": "...", "next_goal": "...", "action": [ { "click": { "index": 12 } } ] // one key per action }, "result": [ { "is_done": false, "success": null, "error": null, "extracted_content": null } ], "state": { "url": "...", "title": "...", "tabs": [ ... ], "interacted_element": [ { "node_name": "BUTTON", "x_path": "...", "bounds": { "x": 0, "y": 0, "width": 0, "height": 0 } } ], "screenshot_path": "screenshots/step_4.png" // v0.13 stores screenshots as FILES, not inline }, "metadata": { "step_number": 4, "step_start_time": 0.0, "step_end_time": 0.0 } } ``` Because v0.13 stores screenshots as separate files referenced by `screenshot_path`, select the screenshot files **together with** the JSON when importing (multi-select or drag them all in) — they are matched by filename. The JSON alone still gives you the full timeline, actions, and reasoning. Older exports that inlined base64 screenshots (`state.screenshot`) and older action names (`click_element_by_index`, `go_to_url`) / element coordinate shapes (`viewport_coordinates`) are also handled. ## What was tested against real Browser Use output — and what was not Honesty section, per the project's own bar: **Tested and true:** - The parser ingests a file **written by browser-use v0.13.7's own serializer** (see above). Loading that file, scrubbing all steps, the element highlight, jump-to-failure (on a variant with a real `ActionResult.error`), and the frame diff were all verified in the deployed app. - The sample run's screenshots, URLs, titles, and element bounding boxes are **real**: they were captured from a live, scripted run of the add-to-cart flow on saucedemo.com (`tools/capture.mjs`, driving headless Chrome over CDP). **Not tested, stated plainly:** - **No end-to-end run driven by an actual LLM.** No LLM API key was available on the build machine, so the sample's `model_output` text (thinking/goals/memory) is authored sample content in the library's real schema — it is labeled "sample data — not an LLM run" in the app. If you run a real agent with `agent.save_history()` and load the export, that is exactly the path the parser was built and validated for — and if it fails on your real export, that is a bug: please open an issue and attach the JSON (minus anything sensitive). - The browser-use history format changes between versions (v0.13 renamed actions and moved screenshots out of the JSON, both handled here). If your version's export deviates further, the app surfaces parse warnings rather than silently guessing — and this README makes no claim of compatibility beyond what is listed above. ## Run a real agent and view it ```python from browser_use import Agent, ChatOpenAI import asyncio async def main(): agent = Agent( task="Log into saucedemo.com as standard_user and add the Sauce Labs Backpack to the cart", llm=ChatOpenAI(model="gpt-4o-mini"), ) history = await agent.run() history.save_to_file("agent_history.json") asyncio.run(main()) ``` Then open AgentScrub and select `agent_history.json` plus the screenshots directory's files. ## Development ``` cd web npm install npm run dev # local dev server npm run build # production build to web/dist ``` - `web/` — the app (Vite + React + TypeScript, no backend, no runtime dependencies beyond React) - `web/src/parse.ts` — the normalizing parser and its format-variant handling - `tools/capture.mjs` — CDP script that captured the sample's real screenshots and element bounds - `tools/build_sample.py` — builds the sample history through browser-use's own classes and round-trip-verifies it - `sample/` — the generated history + captured screenshots ## Architecture note Fully client-side by design: no server, no cold starts, nothing leaves the browser. A debugging tool for run artifacts should work the moment you land on it with a file in hand.