The single most common failure in browser automation is a reference that was correct two steps ago and is not correct now, because the page re-rendered. The textbook response is to retry, but retrying the same dead reference fails again. The fix is to take a fresh snapshot of the page the moment any tool call throws, and let the model pick a new reference from the live tree.
Before you start
A browser agent that can capture a fresh accessibility tree or DOM snapshot, and a page that re-renders during the task.
Catch the stale error, do not retry blindly
When a tool call throws a stale element error, stop the retry loop immediately. The reference is dead: retrying it will fail the same way.
Log the error with the step number and the reference that went stale, so you can see whether one page or one action causes most of the failures.
Re-snapshot the page right away
Call the snapshot tool again and slice the fresh accessibility tree to a size the model can use, such as 2,000 characters, and put it into the failed tool’s result string. The model’s next turn sees a tree that reflects the actual page.
Do not reuse any part of the old tree: the re-render may have moved, renamed or removed the elements the old tree described.
Pick the new reference and continue
Let the model pick a new reference from the fresh tree and continue the task. If the element is gone entirely, the agent should say so and stop, not guess at a different element.
If the same step goes stale three times, the page is too unstable for this approach: switch to a deterministic locator or a scripted path for that step.
Practice check: fictional Maple Corner form task, 12 steps, 2 stale errors
The table below is fictional practice material, worked out by hand from the stated recovery. It is the expected result for the practice run, not a run of any agent.
| Step | Error | Recovery | Outcome | Verdict |
|---|---|---|---|---|
| 5 | Stale element | Fresh snapshot | New ref picked | Pass |
| 6 | None | Continued | Field filled | Pass |
| 9 | Stale element | Fresh snapshot | New ref picked | Pass |
| 12 | None | Submitted | Form sent | Pass |
Both stale errors are recovered by re-snapshotting: the agent picks a new reference from the live tree and the form is submitted at step 12. No step is retried on a dead reference.
Expected result. UNTESTED: the steps in the practice table are worked out by hand, not measured by running a browser agent. Catch the next stale element error in your own run, re-snapshot the page, and let the model pick a new reference from the fresh tree.
Limits
- A stale reference is dead: retrying it is the most common way to waste a run.
- If the page re-renders constantly, the fix is a stable locator or a scripted path, not more snapshots.
