Repository navigation
Conversation
…reenshot
`snapshot -a` exits 1 with "Selector matched multiple elements" on most real
pages, so /qa, /canary and /land-and-deploy silently produce reports whose
screenshots do not exist. Plain `screenshot <path>` is unaffected.
Refs are built as getByRole(role, {name}) and disambiguated with .nth() when
role+name repeats. That disambiguation cannot fire for a node with NO accessible
name: the locator degrades to getByRole(role) with no name filter, and the count
driving .nth() is taken from the FILTERED aria snapshot while getByRole matches
the unfiltered DOM. Measured on a live page: the tree surfaced 2 unnamed
paragraphs, the DOM had 9. Landmarks (banner/main/contentinfo) and paragraphs are
correctly unnamed per ARIA, so this is the common case rather than an edge case.
boundingBox() then hits Playwright strict mode, and the catch allowlisted only
timeout/closed/Target/Execution-context messages — so the strict-mode error was
re-thrown and aborted every remaining annotation.
Two changes:
- `.first()` before boundingBox(), so an ambiguous ref draws a box on its first
match instead of aborting. The heatmap path below has always tolerated this via
a bare `catch {}`; annotate was the only path that could be killed outright.
- the catch no longer re-throws on unrecognised messages. A box we cannot measure
is a box we do not draw, never a reason to lose the rest of the page. Set
BROWSE_DEBUG to see what was skipped.
Also: `-o` passed without `-a`/`-H` was silently ignored (exit 0, no file), which
reads as "screenshots are broken" rather than "you forgot a flag". It now warns
and points at `browse screenshot <path>`.
Verified by rebuilding both ways against the same page with 51 refs present:
before — "Selector matched multiple elements", no file written
after — exit 0, 229KB PNG
|
Merging to
After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here |
Contributor
|
Thanks for this, @namtrok. The fix is now on main: snapshot handles ambiguous refs by taking .first() and reporting them instead of failing the annotated screenshot (browse/src/snapshot.ts) (fixed in v1.68.0.0, #2632). Closing as superseded; if you still see the problem on the latest gstack, please open an issue with ./setup --status output. |
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.
The symptom
browse snapshot -aexits 1 withSelector matched multiple elementson most real-world pages. Because-ais hardcoded inqa/SKILL.md(3 sites),canary/SKILL.md(3 sites) andland-and-deploy/SKILL.md, those skills silently produce reports whose screenshots do not exist — the command fails, the report still references a path, and a stale file from a previous run makes it look fine.Plain
browse screenshot <path>is unaffected, which is what makes this easy to miss.Root cause
Refs are built as
getByRole(role, { name })and disambiguated with.nth()when a role+name pair repeats (snapshot.ts:210-229). That works for duplicate named elements.It cannot fire for a node with no accessible name. The locator degrades to
getByRole(role)with no name filter, and the count driving.nth()comes from the filtered aria snapshot whilegetByRolematches the unfiltered DOM. Measured on a live page: the tree surfaced 2 unnamedparagraphnodes; the DOM had 9.boundingBox()then trips Playwright strict mode. The catch atsnapshot.ts:396-399allowlisted onlyTimeout/closed/Target/Execution context, so the strict-mode error was re-thrown and one ambiguous ref aborted every remaining annotation.Worth stressing: landmarks (
banner,main,contentinfo) andparagraphare correctly unnamed per ARIA. On the page I reproduced against, 7 refs had no name and the three<nav>elements were all properly labelled — so this fires on well-built pages, not broken ones. It is the common case.The fix
.first()beforeboundingBox()— an ambiguous ref draws a box on its first match instead of aborting. The heatmap path at what is now line ~538 has always tolerated this with a barecatch {}; annotate was the only path that could be killed outright.BROWSE_DEBUG=1prints what was skipped.-owithout-a/-Hnow warns instead of silently doing nothing (exit 0, no file). That silence reads as "screenshots are broken" rather than "you forgot a flag", and cost a real debugging session.Verification
Rebuilt both ways and ran the identical command against the identical page, with a positive control that refs actually existed (51 present, so the test could not pass vacuously):
mainSelector matched multiple elements— no file writtenThe only variable between the two runs is this diff.
Note
No test added.
browse/test/has no fixture that reproduces this — it needs a page with an unnamed landmark whose role also appears more often in the DOM than in the aria snapshot. Happy to add one if you'd like a particular shape.