Bug: detect_pagination_buttons false positives — substring matching ('preview'→prev) and any 1-2 digit text → page_number
Browser Use Version
main @ 85ddbfed (2026-08-19)
Bug Description
DomService.detect_pagination_buttons (browser_use/dom/service.py, around L1204-1217) produces a large number of false positives due to two independent issues in the classification logic. This is related to but distinct from #4620 (symbol ambiguity, already fixed) — the problems below affect word patterns and numeric buttons.
(a) Unanchored substring matching
all_text = f'{text} {aria_label} {title} {class_name}'.strip()
...
elif any(pattern in all_text for pattern in prev_patterns): # 'prev' ⊂ 'preview'
Any element whose combined text/aria/title/class merely contains a pattern word is classified:
- "Preview" link (
class="preview-link") →prev(because'prev' in 'preview-link') - "Last modified" sort control →
last - "Last name" column header →
last - "Next steps" wizard button →
next - Filter with
aria-label="price < 100"→prev(because'<'is a pattern)
The class name being included in all_text makes this worse: CSS frameworks routinely contain tokens like last-child, next-step, preview-.
(b) Any 1-2 digit clickable text is a page_number
elif text.isdigit() and len(text) <= 2 and role in ['button', 'link', '']:
button_type = 'page_number'
role='' (i.e. no explicit ARIA role — the majority of plain HTML elements) qualifies, so virtually any short numeric label is classified:
| Element | Classified as |
|---|---|
| Datepicker calendar day cells "1" "15" "31" | page_number |
| Star-rating button "5" | page_number |
| Shoe-size selector "38" | page_number |
| Quantity stepper "10" | page_number |
| Cart badge "3" | page_number |
Verification
I ran a pure-logic reproduction of the function against 16 realistic clickable elements (real pagination + the widgets above): 16/16 were flagged as pagination buttons, 13 of them false positives.
Impact
pagination_buttons is surfaced to the LLM through BrowserStateSummary. On any page containing a datepicker, rating widget, size selector, or "preview"-style links, the model is told these are pagination controls — e.g. it may click calendar day "15" believing it's page 15, or waste steps on misidentified controls.
Suggested fix
- Anchor the word-pattern matches (exact equality or word-boundary regex on
text/aria_label/titleseparately), and dropclass_namefrom the match input (or match it against anchored CSS token lists). - For
page_number: require an explicitroleofbutton/link(drop''), and require the candidate's siblings to form a numeric run (2+ consecutive integers) or that its ancestor is anav/pagination container — a lone "5" in a rating widget would then be excluded.
Since the heuristics are a design trade-off (recall vs precision) I'm opening this as an issue for discussion first; happy to contribute a PR with tests for whatever approach you prefer.
Good write-up — the 13/16 false-positive rate matches what substring matching over a class_name-joined string produces in practice: framework utility classes (last-child, next-step, preview-*) guarantee that path fires on pages that don't even render a paginator.
A few additions I'd fold into the fix before a PR lands:
-
Anchor the container before the label. Word/number rules should be the second test, not the first. First test the pagination container semantics:
nav[aria-label*="pagination"]/[role="navigation"],rel="prev|next"links,[aria-label]containing "page"/"pagination"/"pager", or aul/ollink cluster with a marked current page. Classify a control as pagination only if it sits inside such a container or is in a run that includes an explicit current-page marker. Out-of-container numeric text then defaults to "not pagination" — datepickers, ratings, and size pickers are rarely wrapped in pagination containers, so that single gate kills most of the table you listed. -
Calendar grids defeat the "2+ consecutive integers" sibling rule. A datepicker renders 28–31 consecutive numbers in a grid — indistinguishable from a numeric run by count alone. What disambiguates: grid/row structure and a highlighted current cell. Requiring the run to be in one inline cluster (same
ul/ol/row) plus onearia-current="page"or active-class marker is a much stronger signal than run length. A numeric cluster with no current-page marker at all is likely not pagination — or is pagination that should be low-confidence anyway. -
Surface confidence instead of a binary.
pagination_buttonscurrently reads as a fact to the LLM, and a wrong pagination action is worse than a missed one (it clicks a calendar day or size selector believing it's page 15). Marking uncertain classifications — out-of-container, no current marker, matched only via legacyclass_nametokens — as low-confidence (or a separatesuspected_pagination_buttonsfield) lets the model weigh the action instead of trusting it. Cheaper than perfecting one heuristic, and gives operators a lever when a specific site's widgets keep tripping it. -
Lock precision with a DOM-snapshot regression corpus. The 16-element repro is a good start, but unit fixtures rot as patterns get added. Snapshots of real pages (a docs site, a category page, a calendar widget) stored as DOM fixtures with expected button types would catch regressions in the same run as the fix PR — this class of bug tends to come back via the next
any(pattern in text)shortcut.
Agreed that dropping role='' is right and low-risk; the container-anchored check is where the remaining precision is.
👋 This issue has been automatically marked as stale because it hasn't had activity for 60 days.
⚡ We've made significant progress recently! Please test with the latest version of browser-use to see if this issue has been resolved. If the issue persists, please let us know by commenting below.
To keep this issue open:
- Add a comment explaining why this is still relevant after testing the latest version
- Add the
pinnedlabel if this is an important long-term issue - Reference it in a PR if you're working on a fix
This will be automatically closed in 14 days if no further activity occurs.
Thanks for contributing to browser-use! 🤖 If you have questions, join our Discord.
🔒 This issue was automatically closed because it was stale for 14 days with no activity.
Don't worry! If this issue is still relevant:
- First, test with the latest version - we've made tons of improvements recently!
- Reopen it if you have permissions and the issue persists
- Create a fresh issue with updated information if the problem still exists after testing the latest version
- Join our Discord to discuss
We appreciate your contribution to browser-use! 🤖