fix(electron): move the pointer before a press's hit test, and press only enabled elements

Closed
KD
8h ago
+188-22

What

Taps, long presses, and drags on an Electron target now land where a person's would, and only when they should:

  • The pointer moves to the element before the engine checks what the point would hit. A menu or overlay that the element's mouseenter opens over it is in that check, and takes no press meant for the element. The press then happens where the pointer already is, with no second move in between.
  • An element Chromium's accessibility tree says is disabled or inert takes no press, even when the page cannot tell (an aria-disabled wrapper around a slot inside a closed shadow root, content behind a modal). Neither does an element its own mouseenter disables.
  • An action whose time ran out while it waited behind another action's input (electron.keyboard.type(..., { delay })) scrolls nothing and moves no pointer. It fails with ACTION_FAILED instead of scrolling the page after the step has already failed.
  • Releasing one Shift key keeps the other one held, and releasing Alt while AltGraph is down sends the release.

Why

  • A press used to hit-test the point, then move the pointer there and press. An overlay a hover opens appeared between the check and the press, and the press went to the overlay.
  • The page-side enabled check reads only what the page can reach, so a disabled state set inside a closed shadow root, or by a modal, was not seen.
  • The actionability probe and scrollIntoView ran on after the budget expired, while they waited for another action's input to finish.

How it works

  1. actionablePoint takes pointerFirst for the press actions (tap, double tap, multi-tap, secondary tap, long press, drag). It moves the pointer to the centre and checks again that the element is enabled, then runs the hit test (packages/electron/src/actionability.ts:78-120).
  2. Mouse.at(x, y) says whether the pointer is already at a point. click, longPress, and drag send no move when it is (packages/electron/src/cdp/input.ts:209-220, packages/electron/src/actions.ts).
  3. heldBack reads the node's own entry in Chromium's accessibility tree (Accessibility.getPartialAXTree) and refuses one that is inert or disabled (actionability.ts:44). waitReady uses it too.
  4. The step's check() calls budget.check(). The probe calls it before it scrolls, before the fallback scroll, and before the pointer move. scrollIntoView calls it before each scroll it polls (actionability.ts:90-111, actions.ts).
  5. Modifier state tracks the left and right keys, so a modifier is released only when both are up. AltGraph releases Alt (input.ts:94).
  6. Integration tests in Electron cover the hover overlay, the closed-shadow disabled wrapper, self-disabling on mouseenter, and the long press and drag. Unit tests cover the modifier keys, and the testbed covers a scroll queued behind slow typing.

Verified

Ran it locally: yes, on macOS (Apple Silicon) with Electron 45.5.0.

  • This branch passes the Electron package's unit and integration tests, the Electron testbed run through the built CLI (pnpm --filter @e2e-dev/electron-testbed test), and pnpm check.
  • 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
unitKeyboard holds a modifier while its key on the other side is still downfailspasses
unitMouse presses where the pointer already is without moving it againfailspasses
integrationa tap presses nothing that the pointer's arrival shows over its targetfailspasses
integrationa tap takes no tap on an element its own mouseenter disablesfailspasses
integrationa button disabled through a closed shadow root takes no tap, as Chromium's tree says it is disabledfailspasses
testbedtests/parity.e2e.ts > what an Electron target shares with the web > scrolls nothing when its time runs out while another action holds the window's inputfailspasses

The keyboard and mouse unit tests run without Electron.

  • Benchmark: pnpm bench:ab --suite electron-testbed (main against this branch) is still running; its table replaces this line when it finishes.
  • 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.

Fresh-context review (Codex gpt-6.2-sol, read-only, on this branch's diff):

  • Fixed: an element that disables itself in mouseenter was pressed (3ac15b228, with a test).
  • Fixed: the fallback scroll ran without a budget check (ff377f96c, no test: it needs DOM.scrollIntoViewIfNeeded to fail at the deadline).
  • Fixed: added the changeset.
  • Dismissed: the pointer move bypasses Budget.send, so a retry repeats a hover. A move commits no action, and web()'s actionability retries hover the same way.
  • Dismissed: the long-press test was said to pass without its fix. It fails with the fix reverted (expected 'cover pressed' to be 'target pressed').

πŸ€– Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Pointer-based actions now more reliably detect overlays and disabled or inert targets before proceeding.
    • Actions waiting on ongoing input stop when their timeout expires, rather than continuing to scroll or move the pointer afterward.
    • Taps and long presses behave more consistently when the pointer is already at the target.
    • Releasing Shift, Alt, and AltGraph keys now preserves the correct modifier state.