fix(electron): read modal-blocked text, display: contents scopes, zoomed boxes, and <base href> links

KD
4h ago
+120-21

What

On an Electron target, locator reads and node positions now match what the page shows:

PageWasNow
Text in the page behind a modal <dialog>not found by getByTextfound, as text behind inert content already was
getByRole('button') inside a display: contents wrapper's scopenot foundfound
A node's box under a page zoom (zoomFactor: 1.5), far down the document18.75 px off, growing down the pagewhere the page draws it
<a href="faq"> on a page with <base href="https://example.com/help/">resolved against the page URLhttps://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

  1. Chromium marks the page behind a modal dialog as ignored with the reason activeModalDialog and keeps none of its text. TreeProjection reads that content from the DOM, as it already did for aria-hidden and inert (packages/electron/src/tree.ts:224).
  2. 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).
  3. 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).
  4. The snapshot reads the document's baseURL, and links resolve against it (locate.ts:95, packages/electron/src/devtools.ts).
  5. 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) and launch.test.ts (42) pass, with its typecheck and oxlint. The two commits after it (4483ca807, 5224a028d) rename adoptText to adoptContent and rewrap a comment; at 5224a028d the unit tests, typecheck, and oxlint pass again. The Electron testbed run through the built CLI (pnpm --filter @e2e-dev/electron-testbed test) and pnpm check passed at b9ab0894d, before the review rounds; CI covers pnpm check at the head.
  • main against this branch: this branch's tests run against origin/main's packages/electron/src. These tests fail there and pass here:
SuiteTestmainthis PR
integrationa modal dialog leaves the page behind it to a text query, with no role, as inert content isfailspasses
integrationnode boxes are where the page draws them under a page zoom, far down the documentfailspasses
integrationa link reads as the page resolves it, against its failspasses
integrationa display: contents wrapper holds the controls in it for a query scoped to itfailspasses
  • 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.

Metricbase 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.open24.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.selectOption4.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.tap4.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.fill3.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.restart1.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.dragTo1.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.pressSequentially1.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.title1.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.window956 ms (955 ms-956 ms)955 ms (953 ms-955 ms)-0.1% (-0.4% to 0.0%)same, under the floor
step electron.waitForWindow939 ms (938 ms-944 ms)940 ms (939 ms-943 ms)+0.1% (-0.6% to +0.7%)same, under the floor
step locator.scrollIntoView928 ms (927 ms-928 ms)927 ms (927 ms-928 ms)-0.1% (-0.2% to +0.1%)same, under the floor
step electron.launch916 ms (914 ms-917 ms)915 ms (915 ms-916 ms)-0.1% (-0.2% to +0.4%)same, under the floor
step locator.longPress905 ms (904 ms-905 ms)906 ms (905 ms-906 ms)+0.1% (-0.1% to +0.3%)same, under the floor
step locator.waitFor903 ms (903 ms-903 ms)903 ms (902 ms-904 ms)+0.1% (-0.2% to +0.2%)same, under the floor
step expect.toHaveValue753 ms (749 ms-756 ms)758 ms (752 ms-761 ms)+0.3% (-0.3% to +1.5%)same, under the floor
step locator.setInputFiles574 ms (573 ms-574 ms)573 ms (572 ms-576 ms)+0.1% (-0.5% to +0.5%)same, under the floor
step electron.waitForDownload518 ms (518 ms-518 ms)518 ms (516 ms-518 ms)0.0% (-0.4% to +0.2%)same
step expect.not.toHaveValue517 ms (517 ms-519 ms)517 ms (514 ms-518 ms)-0.2% (-1.2% to +0.5%)same, under the floor
step electron.evaluate488 ms (485 ms-490 ms)488 ms (485 ms-490 ms)-0.1% (-1.2% to +1.4%)same, under the floor
step expect.toBeVisible447 ms (445 ms-448 ms)454 ms (441 ms-455 ms)+1.5% (-3.4% to +4.4%)same, under the floor
step app.clearState339 ms (339 ms-341 ms)339 ms (338 ms-339 ms)-0.1% (-0.9% to +0.6%)same, under the floor
step expect.toHaveText338 ms (335 ms-346 ms)338 ms (336 ms-343 ms)-0.0% (-1.6% to +1.7%)same, under the floor
step locator.check317 ms (316 ms-318 ms)318 ms (317 ms-320 ms)+0.6% (-0.5% to +1.4%)same, under the floor
step app.screenshot126 ms (119 ms-133 ms)125 ms (122 ms-127 ms)-2.2% (-5.7% to +6.4%)same, under the floor
step expect.toHaveCount99 ms (98 ms-100 ms)100 ms (99 ms-101 ms)+0.5% (-0.5% to +2.6%)same, under the floor
step app.stopRecording86 ms (85 ms-86 ms)85 ms (85 ms-85 ms)-1.2% (-3.5% to +0.0%)same, under the floor
step locator.press50 ms (49 ms-51 ms)51 ms (50 ms-51 ms)0.0% (0.0% to +5.2%)same
step locator.clear49 ms (48 ms-49 ms)50 ms (49 ms-50 ms)+2.1% (-2.1% to +4.1%)same, under the floor
step locator.focus37 ms (36 ms-37 ms)36 ms (36 ms-37 ms)-1.4% (-4.1% to +4.2%)same, under the floor
step locator.swipe35 ms (35 ms-35 ms)35 ms (35 ms-36 ms)0.0% (-2.8% to +4.3%)same
step electron.keyboard.press32 ms (32 ms-34 ms)33 ms (32 ms-34 ms)0.0% (-2.9% to +9.3%)same
step expect.toBeChecked32 ms (31 ms-32 ms)32 ms (32 ms-33 ms)+4.6% (0.0% to +6.6%)same, under the floor
step app.startRecording23 ms (23 ms-23 ms)23 ms (23 ms-23 ms)0.0% (-2.2% to +4.4%)same
step expect.toBeHidden21 ms (20 ms-22 ms)21 ms (21 ms-22 ms)+2.4% (-9.5% to +5.0%)same, under the floor
step expect.toBeDisabled21 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.type21 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.toBeChecked20 ms (18 ms-20 ms)21 ms (19 ms-21 ms)+5.3% (-0.0% to +11.1%)same, under the floor
step expect.toBeEditable19 ms (18 ms-19 ms)19 ms (18 ms-19 ms)0.0% (-5.3% to +5.6%)same
step locator.uncheck17 ms (16 ms-17 ms)16 ms (16 ms-16 ms)-3.0% (-5.9% to +3.1%)same, under the floor
step expect.toHaveAttribute13 ms (12 ms-13 ms)12 ms (12 ms-13 ms)0.0% (-7.7% to +8.7%)same
step locator.hover13 ms (9 ms-16 ms)10 ms (9 ms-15 ms)0.0% (-25.0% to +3.3%)same
step locator.dblclick12 ms (12 ms-13 ms)13 ms (12 ms-13 ms)0.0% (-3.9% to +13.2%)same
step expect.toBeInViewport11 ms (11 ms-12 ms)11 ms (11 ms-12 ms)0.0% (-8.7% to +8.7%)same
step electron.keyboard.down11 ms (10 ms-11 ms)10 ms (10 ms-11 ms)0.0% (-13.8% to +4.9%)same
step electron.keyboard.up10 ms (10 ms-10 ms)10 ms (10 ms-10 ms)0.0% (-9.5% to 0.0%)same
step expect.not.toBeEmpty10 ms (10 ms-11 ms)10 ms (9 ms-11 ms)0.0% (-14.2% to +10.6%)same
step expect.toBeEmpty10 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.toBeEditable9 ms (8 ms-9 ms)9 ms (8 ms-9 ms)0.0% (-5.7% to +6.1%)same
step expect.not.toBeInViewport9 ms (9 ms-9 ms)9 ms (9 ms-9 ms)0.0% (-5.1% to +5.4%)same
step window.reload8 ms (8 ms-8 ms)8 ms (8 ms-8 ms)0.0% (-6.5% to +6.9%)same
step expect.toContainText8 ms (8 ms-8 ms)8 ms (8 ms-8 ms)0.0% (0.0% to +6.9%)same
step expect.not.toHaveAttribute6 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.toBeHidden6 ms (6 ms-6 ms)6 ms (5 ms-6 ms)0.0% (-16.7% to 0.0%)same
step electron.keyboard.insertText6 ms (5 ms-6 ms)5 ms (5 ms-6 ms)0.0% (-16.7% to +9.5%)same
step screen.tree5 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.toHaveRole5 ms (4 ms-5 ms)4 ms (4 ms-4 ms)-10.6% (-20.0% to 0.0%)same, under the floor
step expect.toHaveRole5 ms (4 ms-5 ms)5 ms (3 ms-5 ms)-8.7% (-25.0% to 0.0%)same, under the floor
step app.back5 ms (4 ms-6 ms)5 ms (4 ms-5 ms)0.0% (-25.5% to +73.2%)same
step expect.toBeFocused4 ms (4 ms-4 ms)4 ms (4 ms-4 ms)0.0% (0.0% to 0.0%)same
step expect.toHaveAccessibleName4 ms (4 ms-4 ms)4 ms (4 ms-4 ms)0.0% (0.0% to +29.1%)same
step expect.toBeSelected4 ms (4 ms-4 ms)4 ms (4 ms-4 ms)0.0% (-10.6% to 0.0%)same
step window.evaluate4 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.toBeEnabled4 ms (4 ms-4 ms)4 ms (4 ms-4 ms)0.0% (0.0% to +11.8%)same
step expect.toHaveScreenshot1 ms (1 ms-1 ms)1 ms (1 ms-1 ms)0.0% (-29.3% to 0.0%)same
step window.close1 ms (1 ms-2 ms)1 ms (1 ms-2 ms)0.0% (-29.3% to +41.4%)same
step window.activate0 ms (0 ms-1 ms)1 ms (0 ms-1 ms)- (- to -)same, under the floor

Counters

Counterbasehead
events navigation128-134126-132
steps579579-580
Tests outside the threshold: 0 of 86

With 86 tests compared at 95%, about 4.3 could land outside by chance.

- Video: none attached. The change is in what the engine reads and when it acts, which the tests above pin down; a recording would show the same window either way. - Local macOS runs, on both sides, started Electron with `-ApplePersistenceIgnoreState YES` from #2500, applied without committing it. Without it, an Electron the tests killed makes macOS ask to reopen its windows, and the next launch waits out its timeout. The Linux and Windows CI jobs do not need it.

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: contents wrappers.
    • Element positioning is more accurate when the page is zoomed or scrolled.
    • Relative links now resolve against the page’s <base href> when present.