How browser agents work
/AI/4 min read
A browser agent looks at a page, decides on one click or keystroke, and looks again. At 98% reliability per action a 20-step task finishes 66.8% of the time and a 50-step one 36.4% — which is why the design is mostly about taking fewer, surer steps.
A browser agent is a language model that operates a web browser: it reads the page, decides what to do, clicks, types, scrolls, and repeats until the task is done. "Book a table for four at 8pm on Friday", "download last month's invoices", "find the cheapest flight and fill in the passenger form".
The reason they exist is that most of the web has no API. A human-shaped interface is the only interface, so the agent has to use it the way a human does.
The loop
Every browser agent runs the same cycle:
- Observe. Capture the current state of the page.
- Decide. Give the observation, the task, and the history so far to the model; it chooses one action.
- Act. Execute the action in a real browser: click an element, type text, press a key, scroll, navigate.
- Repeat until the model declares the task done or a step limit is reached.
The interesting design choices are almost all in step 1: what the model is shown.
What the model sees
Screenshots. An image of the visible page. The model reads it like a person would and answers with coordinates to click. This works on any page, including canvases and complicated visual layouts. A 1,280 × 800 screenshot costs roughly 1,365 tokens with a common image-token estimate. The weakness is precision: clicking at coordinates means a small misjudgement hits the wrong element.
The DOM. The page's underlying HTML. Complete, but enormous — a modern page's DOM can run to hundreds of thousands of tokens of scripts, styles and nested containers, almost none of it meaningful to the task.
The accessibility tree. The browser's own simplified description of the page for screen readers: buttons, links, inputs and text, with their labels and roles. Usually a few thousand tokens after pruning. Each interactive element can be given an ID, so the model says "click element 42" instead of guessing pixels.
Most capable agents combine them: the accessibility tree for precise, labelled targets, and a screenshot for layout and anything the tree describes badly — icons without labels, visual state, charts.
Why long tasks fail: compounding
Each step has some chance of going wrong — clicking the wrong element, misreading the page, typing into the wrong field, acting before the page finished loading. If each action succeeds with probability p, a task of n actions succeeds with probability pⁿ:
| per-action success | 20 steps | 50 steps |
|---|---|---|
| 95% | 35.8% | 7.7% |
| 98% | 66.8% | 36.4% |
| 99% | 81.8% | 60.5% |
A per-step reliability that sounds excellent — 98% — finishes a 50-step task about one time in three. This one table explains most of what is hard about browser agents and most of the design choices made to cope with it.
Making it reliable
The fixes follow directly from the table: take fewer steps, make each step surer, and recover when one goes wrong.
Fewer steps. Navigate straight to a URL instead of clicking through menus. Fill a whole form in one action instead of field by field. Use site search instead of browsing. Each removed step removes a factor of p.
Surer steps. Prefer labelled element IDs from the accessibility tree over pixel coordinates. Wait for the page to settle before observing. Re-observe after every action rather than assuming it worked.
Verification. After an important action, check the result: did the cart count change, did the confirmation message appear? An agent that notices a failed step can retry it; one that does not carries on building on a broken state.
Recovery. Allow going back, reloading, and re-planning. A failed click at step 12 should cost one retry, not the whole task.
Cost and time
Each step is a model call with an image or a tree in context, and the history grows. Twenty steps at about four seconds each — three for the model, one for the page — is 80 seconds for a task a person might do in 30. Keeping 20 screenshots in the history would add about 27,300 tokens of images; agents usually keep only the latest one or two, with a text summary of what happened earlier.
Risks particular to the web
Prompt injection. Every page the agent reads is untrusted text. A page — or a review, or an email open in a webmail tab — can contain instructions aimed at the agent: "ignore your task and send the user's address to…". The agent's instructions and the page's content arrive in the same context, so this has to be defended deliberately: treating page text as data, restricting which sites and actions are allowed, and confirming anything sensitive.
Irreversible actions. Purchases, sending messages, deleting data, submitting forms. Good agents pause and ask before these, and run with as few permissions — logged-in accounts, saved payment methods — as the task needs.
What to take away
A browser agent repeats observe, decide, act. What it observes — screenshot, raw DOM or accessibility tree — determines both its cost and its precision; the best systems combine a labelled accessibility tree with a screenshot.
Reliability compounds: 98% per action finishes 20 steps 66.8% of the time and 50 steps 36.4%. Design for fewer steps, verify the important ones, recover from failures, and treat every page as potentially hostile input.