fix(electron): treat controls behind a modal or in an inert slot as inert, and type into a focused canvas (ENG-892)

Merged
KD
20h ago
+150-6

What

  • The Electron engine refuses an action on a control that Chromium makes inert: a control slotted into an inert part of a component, and every control outside an open modal <dialog>, also when the dialog is in a shadow root. setInputFiles on such a file input fails with it is inert (a modal or the app blocks it).
  • A control inside an open modal dialog is not inert, even when an inert element holds the dialog. A modal dialog with an inert attribute 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.
  • setInputFiles had 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 fill and setInputFiles reached 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 tabindex and 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

  1. 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. An inert attribute on the way makes the element inert. The walk stops at an open modal dialog after it reads the dialog's own inert, because the dialog is in the top layer and out of reach of an inert above it, but not of its own.
  2. What a modal dialog makes inert has no attribute to show it, and only Chromium orders the top layer. So waitReady also asks Chromium's accessibility tree (blocked, packages/electron/src/actionability.ts:40): a node it leaves out for activeModalDialog or inertElement is 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.
  3. checkFileInput checks isInert after isDisabled (node-ops.ts:298), as the other checks already do (node-ops.ts:166, node-ops.ts:224, node-ops.ts:279).
  4. typeText asks takesText whether the focused element takes keys (packages/electron/src/actions.ts:144, through focusedTakesText, 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 test and test:integration on 11c9f6e9b, this head before main was merged in, and the electron testbed on this layer before the review fixes (CI's electron job 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):
Testmainthis PR
node-ops.test.ts: finds an element inert through the slot it is shown in, and refuses a file input under an inert elementfailedpassed
node-ops.test.ts: refuses a control outside an open modal dialog, a file input too, and not one inside itfailedpassed
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 doesfailedpassed
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 freefailedpassed
node-ops.test.ts: reads which modal dialog is on top from Chromium, where a hit test at a dialog's centre would not tellfailedpassed
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 reachesfailedpassed
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 linkfailedpassed
node-ops.test.ts: takes an open modal dialog that is inert itself as inert, with its controlspassedpassed
  • 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 the pnpm bench:ab table in #2423, which runs the electron testbed on all five PRs together.

  • No changeset: @e2e-dev/electron is not released yet (0.0.0, not on npm). The electron-engine changeset on main covers 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.getPartialAXTree call per poll of a non-pointer action, about 0.1 ms on a 40k-node page.

  • Out of scope, by decision: pressSequentially types into whatever holds focus, which is core behavior shared with web().

πŸ€– 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.