You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(browser): rank dialog and viewport elements before truncating (#2) - #8
On busy pages with large navigation bars or complex layouts (e.g. cloud dashboards), browser_elements previously truncated elements at 150 strictly in document order. Consequently, modal dialog fields and buttons appearing after 150 navigation links were never returned.
This PR ranks elements before truncation:
Tier 0: Elements inside an open <dialog open> or [role=dialog] / [role=alertdialog].
Tier 1: Elements visible in the current viewport (r.bottom > 0 && r.top < innerHeight && r.right > 0 && r.left < innerWidth).
Tier 2: Visible elements rendered outside the current viewport.
Document order is preserved within each tier.
Changes
src/browser.ts: Updated ELEMENTS_JS to compute element ranking and sort candidate controls stably before assigning IDs (e1, e2, ...) and truncating to 150 items.
tests/browser.test.ts: Added comprehensive unit test coverage:
Verifies ranking precedence: dialog controls first, then viewport elements, then offscreen elements.
Verifies preservation of modal dialog controls even when preceded by >150 sidebar items in document order.
Closing this as superseded rather than rebasing it — there is no union left to keep.
main now ranks before cutting to 150, in commit b06c2c4 ("Browser tools round 7: single-page apps, ranking before the 150 cap, search boxes"), and that implementation covers the same three tiers this PR introduced and more:
src/browser.ts builds const rank = el => { if (inPopup(el) || popupRole(el)) return 0; const r = __rect(el); return r.top + r.height > 0 && r.top < innerHeight && r.left < innerWidth && r.left + r.width > 0 ? 1 : 2 }, then ranked() sorts by a.r - b.r || a.i - b.i (rank, then page order — the same stable tie-break this PR used) before order.slice(0, 150).
Its tier 0 is broader than mine: dialog[open], [role=dialog], [role=alertdialog], [aria-modal=true] (taking the topmost with .pop()), plus [role=menu], [role=listbox] containers, open menu/option roles via popupRole, and elements whose shadow host is inside a popup. Mine only matched dialog[open] / [role=dialog] / [role=alertdialog] through closest().
Coordinates come from __rect(), which adds ancestor frame offsets, so the viewport tier works inside iframes — this PR used the raw getBoundingClientRect().
That is why the branch reports CONFLICTING instead of needing a mechanical rebase: both sides rewrote the same block of src/browser.ts (and the matching tests) to do the same thing, and main's version is the better one.
Two things that are still open, and I'd rather raise them honestly than smuggle them into a dead branch:
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
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.
Summary
Closes #2
On busy pages with large navigation bars or complex layouts (e.g. cloud dashboards),
browser_elementspreviously truncated elements at 150 strictly in document order. Consequently, modal dialog fields and buttons appearing after 150 navigation links were never returned.This PR ranks elements before truncation:
<dialog open>or[role=dialog]/[role=alertdialog].r.bottom > 0 && r.top < innerHeight && r.right > 0 && r.left < innerWidth).Document order is preserved within each tier.
Changes
src/browser.ts: UpdatedELEMENTS_JSto compute element ranking and sort candidate controls stably before assigning IDs (e1,e2, ...) and truncating to 150 items.tests/browser.test.ts: Added comprehensive unit test coverage:Test Plan
npm test: all 175 tests pass (0 failures).