fix(electron): treat controls behind a modal or in an inert slot as inert, and type into a focused canvas (ENG-892)
What
- The Electron engine refuses an action on a control that Chromium makes inert: a control slotted into an
inertpart of a component, and every control outside an open modal<dialog>, also when the dialog is in a shadow root.setInputFileson such a file input fails withit is inert (a modal or the app blocks it). - A control inside an open modal dialog is not inert, even when an
inertelement holds the dialog. A modal dialog with aninertattribute of its own is inert, with its controls. With two modal dialogs open, the lower one's controls are inert, as Chromium has them. A modal dialog in a closed shadow root, which no page-side check can see, makes the rest of the page inert too. - Typing into the focused element reaches a focused canvas, or a focusable widget with its own key handlers, as on the web. Before, it failed with
nothing that takes text has keyboard focus.
Why
The first PR of the stack for the review of #2237 (ENG-892), which added @e2e-dev/electron. Three review rounds found these defects in the engine's actions:
- The inert check walked DOM parents and shadow hosts. A light-DOM control slotted into an inert subtree passed, and so did every control outside an open modal dialog, which
showModal()makes inert with no attribute. A test could tap a control that a user cannot reach. setInputFileshad no inert check.- In review: the walk stopped at any open modal dialog, but Chromium leaves only the top one free, so with two stacked modal dialogs
fillandsetInputFilesreached the lower one's controls. A page-side hit test at a dialog's centre cannot tell which one is on top either, so the check now reads it from Chromium. - Focused typing took only text fields, editing hosts, and typeahead roles. A canvas editor or a widget with a
tabindexand its own key handlers was refused after it took focus, though the engine contract names a field drawn on a canvas as a target for focused keys.
How it works
isInert(packages/electron/src/in-page/node-ops.ts:118) walks the rendered tree: the slot an element is assigned to, else its parent, else the shadow host of its root. Aninertattribute on the way makes the element inert. The walk stops at an open modal dialog after it reads the dialog's owninert, because the dialog is in the top layer and out of reach of aninertabove it, but not of its own.- What a modal dialog makes inert has no attribute to show it, and only Chromium orders the top layer. So
waitReadyalso asks Chromium's accessibility tree (blocked,packages/electron/src/actionability.ts:40): a node it leaves out foractiveModalDialogorinertElementis inert. That covers controls outside every open modal dialog, the controls of a modal dialog another one covers, and whatever a closed shadow root holds, which no page-side walk can see. checkFileInputchecksisInertafterisDisabled(node-ops.ts:298), as the other checks already do (node-ops.ts:166,node-ops.ts:224,node-ops.ts:279).typeTextaskstakesTextwhether the focused element takes keys (packages/electron/src/actions.ts:144, throughfocusedTakesText, which follows focus into closed shadow roots).takesText(node-ops.ts:351) refuses only the page itself (body,documentElement), a select, a button, and a link, HTML or SVG, when no earlier rule matched. Any other focused element opted into keys. This is the web engine's rule.
Issue
Part of ENG-892. Stack: this PR β #2420 β #2421 β #2422 β #2423.
Verified
Ran it locally: yes
pnpm --filter @e2e-dev/electron testandtest:integrationon 11c9f6e9b, this head beforemainwas merged in, and the electron testbed on this layer before the review fixes (CI'selectronjob runs it on this head):
@e2e-dev/electron unit + integration: Tests 150 passed (150)
apps/electron-testbed: Tests 75 passed (75)
- The new tests of this PR on the code of
main(the bug) and on this PR (the fix):
| Test | main | this PR |
|---|---|---|
node-ops.test.ts: finds an element inert through the slot it is shown in, and refuses a file input under an inert element | failed | passed |
node-ops.test.ts: refuses a control outside an open modal dialog, a file input too, and not one inside it | failed | passed |
node-ops.test.ts: takes a modal dialog in a shadow root as open, and a modal under an inert element as out of its reach, as Chromium does | failed | passed |
node-ops.test.ts: takes the controls of a modal dialog another one covers as inert, centred over it or not, and the top one's as free | failed | passed |
node-ops.test.ts: reads which modal dialog is on top from Chromium, where a hit test at a dialog's centre would not tell | failed | passed |
node-ops.test.ts: refuses a control a closed shadow root makes inert, by a modal dialog or an inert slot, which no page-side walk reaches | failed | passed |
node-ops.test.ts: lets a focusable element with key handlers of its own take keys, as a canvas editor does, and not the page or a link | failed | passed |
node-ops.test.ts: takes an open modal dialog that is inert itself as inert, with its controls | passed | passed |
-
The last row guards the walk's stop at an open modal dialog: on 0d7cadc77 it failed, because the walk stopped before it read the dialog's own
inert. In review, a focused SVG link also took typed text; the canvas-editor test now checks an SVG link as well. -
Behavior and timing against
main: see thepnpm bench:abtable in #2423, which runs the electron testbed on all five PRs together. -
No changeset:
@e2e-dev/electronis not released yet (0.0.0, not on npm). Theelectron-enginechangeset onmaincovers its first release. -
Not clean: the fixes come from review rounds with four models. Later rounds over the whole engine found more defects; those go in a follow-up PR on top of this stack.
-
The Chromium check is one
Accessibility.getPartialAXTreecall per poll of a non-pointer action, about 0.1 ms on a 40k-node page. -
Out of scope, by decision:
pressSequentiallytypes into whatever holds focus, which is core behavior shared withweb().
π€ Generated with Claude Code
Summary by CodeRabbit
- Bug Fixes
- Controls blocked by inactive page areas or modal dialogs are no longer treated as ready for interaction, including controls inside shadow roots or slotted content. Readiness checks continue waiting when a control is blocked, and timeouts identify inertness when applicable.
- File inputs in blocked areas are correctly rejected, while available file inputs remain usable.
- Text entry is recognized for keys handled by an application on focusable elements. The page background, dropdowns, buttons, and links remain excluded.