fix(electron): read modal-blocked text, display: contents scopes, zoomed boxes, and <base href> links
What
On an Electron target, locator reads and node positions now match what the page shows:
| Page | Was | Now |
|---|---|---|
Text in the page behind a modal <dialog> | not found by getByText | found, as text behind inert content already was |
getByRole('button') inside a display: contents wrapper's scope | not found | found |
A node's box under a page zoom (zoomFactor: 1.5), far down the document | 18.75 px off, growing down the page | where the page draws it |
<a href="faq"> on a page with <base href="https://example.com/help/"> | resolved against the page URL | https://example.com/help/faq |
Why
getByText behind a modal dialog, a query scoped to a display: contents wrapper, and getByRole('link') with an href gave a different answer on electron() than on web() for these pages. Taps under a page zoom landed off target far down a document.
How it works
- Chromium marks the page behind a modal dialog as ignored with the reason
activeModalDialogand keeps none of its text.TreeProjectionreads that content from the DOM, as it already did foraria-hiddenandinert(packages/electron/src/tree.ts:224). - When the tree leaves out a wrapper, the wrapper adopts the elements the tree kept inside it, not only its text runs, so a query scoped to it finds them. With no text run among them, its text still comes from the DOM, as on main, so hidden content inside it keeps its text (
tree.ts:388). - Box positions are scaled with the visual viewport's sizes, which are exact, instead of the layout viewport's whole pixels (
packages/electron/src/locate.ts:46). - The snapshot reads the document's
baseURL, and links resolve against it (locate.ts:95,packages/electron/src/devtools.ts). - Each row has an integration test in Electron (
packages/electron/tests/integration/launch.test.ts:416-491).
Left out: an earlier version also read locator text by computed display (one word across a soft wrap, a shown <br> or block boundary as a space). Each review round found a page it read wrong, last <a><span style="display:block">Home</span></a>Next, which main reads correctly as Home Next. A soft wrap inside one word is rare, so this PR keeps main's text joining.
Verified
Ran it locally: yes, on macOS (Apple Silicon) with Electron 45.5.0.
- At
3b66dca1b, the Electron package's unit tests (114) andlaunch.test.ts(42) pass, with its typecheck and oxlint. The two commits after it (4483ca807,5224a028d) renameadoptTexttoadoptContentand rewrap a comment; at5224a028dthe unit tests, typecheck, and oxlint pass again. The Electron testbed run through the built CLI (pnpm --filter @e2e-dev/electron-testbed test) andpnpm checkpassed atb9ab0894d, before the review rounds; CI coverspnpm checkat the head. - main against this branch: this branch's tests run against
origin/main'spackages/electron/src. These tests fail there and pass here:
| Suite | Test | main | this PR |
|---|---|---|---|
| integration | a modal dialog leaves the page behind it to a text query, with no role, as inert content is | fails | passes |
| integration | node boxes are where the page draws them under a page zoom, far down the document | fails | passes |
| integration | a link reads as the page resolves it, against its | fails | passes |
| integration | a display: contents wrapper holds the controls in it for a query scoped to it | fails | passes |
- Benchmark:
pnpm bench:ab --suite electron-testbed, the merge base with main against this head, on a Mac. Both builds ran with-ApplePersistenceIgnoreState(#2500) applied locally and uncommitted, since without it a launch after a killed app stalls 120 s on the reopen-windows alert. The "uncommitted changes" in the header are that line.
Result: the suite and every step are the same (suite -0.1%, 95% CI -0.1% to +0.0%), and the step counts match. One fixture test (mouse moves) changes its step sequence between runs of the same build, as it does on main, so it is noise.
bench:ab output
bench-ab: 7c1b2b25 (merge base with origin/main) vs 5224a028 + uncommitted changes
apps/electron-testbed: e2e run --workers 1. 6 pairs in random order, resolved after 6 pairs. Threshold ±5% and 10 ms. darwin arm64, Apple M5 Pro x18, Node 26.13.1, load 2.5.
Behavior
These tests are left out of the timing rows below.
- unstable on head (2 different step sequences) tests/fixture.e2e.ts › electron.keyboard and a window's page › moves, presses, and scrolls with the mouse where the test points it (electron)
Timings
Every row but the process wall clock covers the 86 tests whose behavior matched.
| Metric | base median (IQR) | head median (IQR) | change (95% CI) | verdict |
|---|---|---|---|---|
| wall (process) | 64.23 s (64.20 s-64.23 s) | 64.21 s (64.17 s-64.23 s) | -0.0% (-0.1% to +0.1%) | same, under the floor |
| suite (sum of attempts) | 63.49 s (63.47 s-63.50 s) | 63.43 s (63.41 s-63.47 s) | -0.1% (-0.1% to +0.0%) | same |
| action (events) | 16.94 s (16.93 s-16.95 s) | 16.93 s (16.92 s-16.94 s) | +0.0% (-0.2% to +0.1%) | same, under the floor |
| step app.open | 24.39 s (24.39 s-24.40 s) | 24.40 s (24.39 s-24.40 s) | +0.0% (-0.0% to +0.1%) | same, under the floor |
| step locator.selectOption | 4.73 s (4.73 s-4.73 s) | 4.73 s (4.73 s-4.74 s) | +0.0% (-0.1% to +0.1%) | same, under the floor |
| step locator.tap | 4.41 s (4.40 s-4.41 s) | 4.40 s (4.40 s-4.40 s) | -0.2% (-0.6% to +0.3%) | same, under the floor |
| step locator.fill | 3.37 s (3.37 s-3.38 s) | 3.38 s (3.37 s-3.38 s) | -0.0% (-0.1% to +0.2%) | same, under the floor |
| step app.restart | 1.99 s (1.99 s-1.99 s) | 1.99 s (1.99 s-1.99 s) | -0.1% (-0.7% to +0.2%) | same, under the floor |
| step locator.dragTo | 1.43 s (1.43 s-1.43 s) | 1.43 s (1.43 s-1.43 s) | -0.2% (-0.4% to +0.2%) | same, under the floor |
| step locator.pressSequentially | 1.08 s (1.08 s-1.09 s) | 1.08 s (1.08 s-1.08 s) | -0.1% (-0.2% to +0.3%) | same, under the floor |
| step window.title | 1.00 s (1.00 s-1.00 s) | 1.00 s (1.00 s-1.00 s) | 0.0% (-0.2% to +0.1%) | same |
| step electron.window | 956 ms (955 ms-956 ms) | 955 ms (953 ms-955 ms) | -0.1% (-0.4% to 0.0%) | same, under the floor |
| step electron.waitForWindow | 939 ms (938 ms-944 ms) | 940 ms (939 ms-943 ms) | +0.1% (-0.6% to +0.7%) | same, under the floor |
| step locator.scrollIntoView | 928 ms (927 ms-928 ms) | 927 ms (927 ms-928 ms) | -0.1% (-0.2% to +0.1%) | same, under the floor |
| step electron.launch | 916 ms (914 ms-917 ms) | 915 ms (915 ms-916 ms) | -0.1% (-0.2% to +0.4%) | same, under the floor |
| step locator.longPress | 905 ms (904 ms-905 ms) | 906 ms (905 ms-906 ms) | +0.1% (-0.1% to +0.3%) | same, under the floor |
| step locator.waitFor | 903 ms (903 ms-903 ms) | 903 ms (902 ms-904 ms) | +0.1% (-0.2% to +0.2%) | same, under the floor |
| step expect.toHaveValue | 753 ms (749 ms-756 ms) | 758 ms (752 ms-761 ms) | +0.3% (-0.3% to +1.5%) | same, under the floor |
| step locator.setInputFiles | 574 ms (573 ms-574 ms) | 573 ms (572 ms-576 ms) | +0.1% (-0.5% to +0.5%) | same, under the floor |
| step electron.waitForDownload | 518 ms (518 ms-518 ms) | 518 ms (516 ms-518 ms) | 0.0% (-0.4% to +0.2%) | same |
| step expect.not.toHaveValue | 517 ms (517 ms-519 ms) | 517 ms (514 ms-518 ms) | -0.2% (-1.2% to +0.5%) | same, under the floor |
| step electron.evaluate | 488 ms (485 ms-490 ms) | 488 ms (485 ms-490 ms) | -0.1% (-1.2% to +1.4%) | same, under the floor |
| step expect.toBeVisible | 447 ms (445 ms-448 ms) | 454 ms (441 ms-455 ms) | +1.5% (-3.4% to +4.4%) | same, under the floor |
| step app.clearState | 339 ms (339 ms-341 ms) | 339 ms (338 ms-339 ms) | -0.1% (-0.9% to +0.6%) | same, under the floor |
| step expect.toHaveText | 338 ms (335 ms-346 ms) | 338 ms (336 ms-343 ms) | -0.0% (-1.6% to +1.7%) | same, under the floor |
| step locator.check | 317 ms (316 ms-318 ms) | 318 ms (317 ms-320 ms) | +0.6% (-0.5% to +1.4%) | same, under the floor |
| step app.screenshot | 126 ms (119 ms-133 ms) | 125 ms (122 ms-127 ms) | -2.2% (-5.7% to +6.4%) | same, under the floor |
| step expect.toHaveCount | 99 ms (98 ms-100 ms) | 100 ms (99 ms-101 ms) | +0.5% (-0.5% to +2.6%) | same, under the floor |
| step app.stopRecording | 86 ms (85 ms-86 ms) | 85 ms (85 ms-85 ms) | -1.2% (-3.5% to +0.0%) | same, under the floor |
| step locator.press | 50 ms (49 ms-51 ms) | 51 ms (50 ms-51 ms) | 0.0% (0.0% to +5.2%) | same |
| step locator.clear | 49 ms (48 ms-49 ms) | 50 ms (49 ms-50 ms) | +2.1% (-2.1% to +4.1%) | same, under the floor |
| step locator.focus | 37 ms (36 ms-37 ms) | 36 ms (36 ms-37 ms) | -1.4% (-4.1% to +4.2%) | same, under the floor |
| step locator.swipe | 35 ms (35 ms-35 ms) | 35 ms (35 ms-36 ms) | 0.0% (-2.8% to +4.3%) | same |
| step electron.keyboard.press | 32 ms (32 ms-34 ms) | 33 ms (32 ms-34 ms) | 0.0% (-2.9% to +9.3%) | same |
| step expect.toBeChecked | 32 ms (31 ms-32 ms) | 32 ms (32 ms-33 ms) | +4.6% (0.0% to +6.6%) | same, under the floor |
| step app.startRecording | 23 ms (23 ms-23 ms) | 23 ms (23 ms-23 ms) | 0.0% (-2.2% to +4.4%) | same |
| step expect.toBeHidden | 21 ms (20 ms-22 ms) | 21 ms (21 ms-22 ms) | +2.4% (-9.5% to +5.0%) | same, under the floor |
| step expect.toBeDisabled | 21 ms (19 ms-22 ms) | 21 ms (20 ms-22 ms) | -2.3% (-6.7% to +21.6%) | same, under the floor |
| step electron.keyboard.type | 21 ms (20 ms-21 ms) | 21 ms (21 ms-21 ms) | +2.5% (-2.3% to +5.0%) | same, under the floor |
| step expect.not.toBeChecked | 20 ms (18 ms-20 ms) | 21 ms (19 ms-21 ms) | +5.3% (-0.0% to +11.1%) | same, under the floor |
| step expect.toBeEditable | 19 ms (18 ms-19 ms) | 19 ms (18 ms-19 ms) | 0.0% (-5.3% to +5.6%) | same |
| step locator.uncheck | 17 ms (16 ms-17 ms) | 16 ms (16 ms-16 ms) | -3.0% (-5.9% to +3.1%) | same, under the floor |
| step expect.toHaveAttribute | 13 ms (12 ms-13 ms) | 12 ms (12 ms-13 ms) | 0.0% (-7.7% to +8.7%) | same |
| step locator.hover | 13 ms (9 ms-16 ms) | 10 ms (9 ms-15 ms) | 0.0% (-25.0% to +3.3%) | same |
| step locator.dblclick | 12 ms (12 ms-13 ms) | 13 ms (12 ms-13 ms) | 0.0% (-3.9% to +13.2%) | same |
| step expect.toBeInViewport | 11 ms (11 ms-12 ms) | 11 ms (11 ms-12 ms) | 0.0% (-8.7% to +8.7%) | same |
| step electron.keyboard.down | 11 ms (10 ms-11 ms) | 10 ms (10 ms-11 ms) | 0.0% (-13.8% to +4.9%) | same |
| step electron.keyboard.up | 10 ms (10 ms-10 ms) | 10 ms (10 ms-10 ms) | 0.0% (-9.5% to 0.0%) | same |
| step expect.not.toBeEmpty | 10 ms (10 ms-11 ms) | 10 ms (9 ms-11 ms) | 0.0% (-14.2% to +10.6%) | same |
| step expect.toBeEmpty | 10 ms (8 ms-10 ms) | 10 ms (9 ms-10 ms) | +5.4% (-10.6% to +18.6%) | same, under the floor |
| step expect.not.toBeEditable | 9 ms (8 ms-9 ms) | 9 ms (8 ms-9 ms) | 0.0% (-5.7% to +6.1%) | same |
| step expect.not.toBeInViewport | 9 ms (9 ms-9 ms) | 9 ms (9 ms-9 ms) | 0.0% (-5.1% to +5.4%) | same |
| step window.reload | 8 ms (8 ms-8 ms) | 8 ms (8 ms-8 ms) | 0.0% (-6.5% to +6.9%) | same |
| step expect.toContainText | 8 ms (8 ms-8 ms) | 8 ms (8 ms-8 ms) | 0.0% (0.0% to +6.9%) | same |
| step expect.not.toHaveAttribute | 6 ms (6 ms-6 ms) | 7 ms (6 ms-7 ms) | +16.7% (-7.4% to +16.7%) | same, under the floor |
| step expect.not.toBeHidden | 6 ms (6 ms-6 ms) | 6 ms (5 ms-6 ms) | 0.0% (-16.7% to 0.0%) | same |
| step electron.keyboard.insertText | 6 ms (5 ms-6 ms) | 5 ms (5 ms-6 ms) | 0.0% (-16.7% to +9.5%) | same |
| step screen.tree | 5 ms (5 ms-6 ms) | 5 ms (5 ms-5 ms) | -8.7% (-18.4% to +11.8%) | same, under the floor |
| step expect.not.toHaveRole | 5 ms (4 ms-5 ms) | 4 ms (4 ms-4 ms) | -10.6% (-20.0% to 0.0%) | same, under the floor |
| step expect.toHaveRole | 5 ms (4 ms-5 ms) | 5 ms (3 ms-5 ms) | -8.7% (-25.0% to 0.0%) | same, under the floor |
| step app.back | 5 ms (4 ms-6 ms) | 5 ms (4 ms-5 ms) | 0.0% (-25.5% to +73.2%) | same |
| step expect.toBeFocused | 4 ms (4 ms-4 ms) | 4 ms (4 ms-4 ms) | 0.0% (0.0% to 0.0%) | same |
| step expect.toHaveAccessibleName | 4 ms (4 ms-4 ms) | 4 ms (4 ms-4 ms) | 0.0% (0.0% to +29.1%) | same |
| step expect.toBeSelected | 4 ms (4 ms-4 ms) | 4 ms (4 ms-4 ms) | 0.0% (-10.6% to 0.0%) | same |
| step window.evaluate | 4 ms (3 ms-4 ms) | 5 ms (4 ms-5 ms) | +25.0% (-10.6% to +49.1%) | same, under the floor |
| step expect.not.toBeEnabled | 4 ms (4 ms-4 ms) | 4 ms (4 ms-4 ms) | 0.0% (0.0% to +11.8%) | same |
| step expect.toHaveScreenshot | 1 ms (1 ms-1 ms) | 1 ms (1 ms-1 ms) | 0.0% (-29.3% to 0.0%) | same |
| step window.close | 1 ms (1 ms-2 ms) | 1 ms (1 ms-2 ms) | 0.0% (-29.3% to +41.4%) | same |
| step window.activate | 0 ms (0 ms-1 ms) | 1 ms (0 ms-1 ms) | - (- to -) | same, under the floor |
Counters
| Counter | base | head |
|---|---|---|
| events navigation | 128-134 | 126-132 |
| steps | 579 | 579-580 |
Tests outside the threshold: 0 of 86
With 86 tests compared at 95%, about 4.3 could land outside by chance.
Review:
- Fixed: added the changeset.
- Fixed: a wrapper that adopted only elements took its text from them alone, so hidden content placed under it later lost its text (
8160fdb2e, with a test). - Reverted: the
display-based text joining and its four follow-up fixes (36357a981); see "Left out" above.
🤖 Generated with Claude Code
Summary by CodeRabbit
- Bug Fixes
- Text queries now work behind modal dialogs, and scoped queries include content inside
display: contentswrappers. - Element positioning is more accurate when the page is zoomed or scrolled.
- Relative links now resolve against the page’s
<base href>when present.
- Text queries now work behind modal dialogs, and scoped queries include content inside