Skip to content

native2: inspect spends its budget on what's on screen first (#178) - #212

Open
iamnbutler wants to merge 2 commits into
mainfrom
fix-inspect-offscreen
Open

iamnbutler wants to merge 2 commits into
mainfrom
fix-inspect-offscreen

Conversation

@iamnbutler

Copy link
Copy Markdown
Contributor

Fixes #178

No new parameter: the default ordering changes.

  • Walk: with visibleFirst (on for desktop_inspect and the fresh observation after an action), an element whose frame lies entirely outside the window's frame is set aside with its subtree and walked after everything on screen, if budget remains. Set-aside children don't count toward the 100-children-per-node limit (it scans up to 10x), so a long list scrolled to its middle reaches the rows on screen. Element IDs are renumbered in tree pre-order at the end, so scope/subtree logic is unchanged.
  • Output bound: bounded now picks the fewest drops by binary search over a tiered order: offscreen first, then non-scope roles, then scope roles. offscreen_omitted counts offscreen elements left out (by the walk's budget or the size limit).
  • A visible_only flag doesn't seem needed: on-screen content now wins the budget, and offscreen elements still fill whatever is left, which keeps scope targets reachable.

Checked on the dev app (native2) with an AppKit fixture: 400 buttons in a scroll view scrolled to the middle. Before: 100 elements listed, all buttons offscreen (btn 0-99, y -5453 to -2483), none visible. After: all 18 visible buttons (btn 190-207) listed, the rest of the 200 filled with offscreen ones, offscreen_omitted: 211. A scoped inspect of the scroll area lists all 405 in pre-order. New CoreTests case for the tiered drop; swift test passes.

The walk sets aside elements entirely outside the window's frame, with their
subtrees, and reads them after everything on screen, then numbers elements in
tree pre-order as before. Set-aside children don't count toward the
per-node child limit. A result over the size limit drops offscreen elements
first, and offscreen_omitted counts what was left out.

Why: native2/Sources/DesktopMac/Elements.swift#fn walk | with visibleFirst, elements are emitted out of order and renumbered by their child-index path at the end; anything that reads element IDs during the walk sees provisional IDs
@iamnbutler
iamnbutler force-pushed the fix-inspect-offscreen branch from c1e7841 to 9f886ab Compare October 25, 2026 01:18
@iamnbutler iamnbutler mentioned this pull request Oct 25, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Accessibility inspect returns far-offscreen elements, blowing the budget on long pages

1 participant