Topic 2 of 4 · 4 min read
Letting agents check UI in a browser
Goal: Set up a loop in which the agent renders the page, compares it with the target and fixes visible differences.
An agent that cannot see the page is guessing; give it a real browser so it can render, look, click and read errors, then fix what it finds. Without that loop, you become the loop: you reload, spot a problem, and describe it in words.
Check yourself · 1 of 3
What does a browser tool add that a type checker and unit tests do not?
Why it matters
Code that compiles can still render a blank page, overlap two panels or throw an error in the console. The type checker and the unit tests do not see any of that. A browser check turns "I think it works" into "I loaded it and it works".
How to set it up
Most agents get a browser through MCP (Model Context Protocol), a standard way to plug tools into an agent. Two common servers are the Playwright MCP server and Chrome DevTools MCP. Both let the agent open a URL, take a screenshot, click, type, and read console messages and network failures. You add the server in the agent's settings, start your dev server, and tell the agent the address.
A good loop has five steps:
- Start the dev server and note the URL.
- Agent opens the page and takes a screenshot.
- Agent compares it with the target image or your written checklist.
- Agent reads the console and network log.
- Agent edits the code, reloads, and repeats until the checklist passes, with a limit such as three rounds.
Before and after
Weak:
Fix the header so it looks right.
Better:
Dev server is on http://localhost:5173.
Open /dashboard at 390px and 1280px wide, screenshot both, and compare with target-header.png.
Fix differences, then reload and confirm the console shows no errors.
Stop after three rounds and list what still differs.
The second prompt names the page, the widths, the target, the console check and a stop rule.
What goes wrong
- Self-approval. The agent looks at its own screenshot and says "matches", while the spacing is off by a third. Give it a checklist of concrete facts: "the button is right-aligned", "no horizontal scroll at 390px".
- Endless loops. Without a round limit, an agent can keep nudging pixels. Set a cap.
- Wrong data. The page renders fine with empty data. Ask it to load a seeded account too.
- Access. A browser tool can open any page it can reach, including logged-in ones. Run it against local or test environments, not production accounts.
Examples
A prompt that drives the loop
The app runs on http://localhost:3000. Open /checkout, add the sample cart, and screenshot at 390px and 1280px.
Checklist: total is right-aligned; the pay button is always visible; no console errors; no failed network calls.
Fix what fails, reload, recheck. Maximum three rounds, then report what is left.
What the agent should report
A useful final message lists each checklist item with pass or fail, the console errors it read, and the screenshots it compared. "Looks good" with no list is a claim, not a check.
Key points
- A browser tool lets the agent render the page, screenshot it, click through it and read console errors, so it stops guessing.
- Playwright MCP and Chrome DevTools MCP are two servers that give agents this ability.
- Give the loop a concrete checklist and a round limit; looking at a screenshot is not proof by itself.
- Test at more than one screen width and with realistic data, not only an empty page.
- Point browser tools at local or test environments rather than production accounts.
Common mistakes
- Asking the agent to "make it look right" with no target and no checklist, so it judges its own work loosely.
- Checking one screen width, then discovering the mobile layout is broken.
- Letting the agent loop with no limit and spending a lot of time on tiny pixel changes.
- Pointing a browser tool at a logged-in production account.
Check yourself · 2 of 3
Why give a browser loop a maximum number of rounds?
Check yourself · 3 of 3
The agent says "the page matches the design". What makes that claim more trustworthy?
Practice items, not counted towards your mastery.
Start here
- Playwright MCP server (Microsoft) (opens in a new tab)ToolFree
The common way to let an agent drive a real browser and take screenshots.
- Chrome DevTools MCP (opens in a new tab)ToolFree
Gives an agent console, network and performance data from Chrome.
- WCAG 2 Quick Reference (W3C) (opens in a new tab)StandardFree
The accessibility success criteria to check agent-built UI against.