Repository navigation
fix(browser): click by index reaches the last read's element - #954
Merged
Merged
Conversation
pageInfoScript stamped data-lich-idx on every read and never removed the stamps of an earlier one. After a scroll and a second read, an element scrolled out of view still carried an index the new read gave to another element, and querySelector, which returns the first match in document order, clicked the stale one with no error.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
pageInfoScriptstampsdata-lich-idxon the visible interactive elements on every read and never removed the stamps of the read before.resolveJSfinds a target withdocument.querySelector('[data-lich-idx="N"]'), the first match in document order. Read the page (button A gets 0), scroll, read again (button B gets 0, A still carries 0 off the viewport):browser_click index 0clicked A, with no error.Fix
Each read removes every existing
data-lich-idxbefore stamping. One line in the script; click, type and press all resolve throughresolveJS, so all three are covered.Why this over a per-read token that makes a stale index fail: the tool contract already says the index is "from the last browser_info", and after this change the DOM holds exactly the last read's indexes. The edge cases land on the error that already exists ("no element matches that target: the page may have changed since it was read; read it again for fresh indexes"):
A token would add an argument to every index target and a field to every page read for the agent to echo back, without catching a case the wipe misses. The MCP tool wording is unchanged: the behavior the agent was promised is now the behavior it gets.
Test plan
TestChromeClickByIndexHitsTheLastReadNotAnEarlierOne(live Chrome, same skip rule as the other live tests): fails before the fix (index 0 from the last read clicked "top", want bottom), passes after.gofmt -l .,go vet ./...,go test ./...green.