fix(electron): move the pointer before a press's hit test, and press only enabled elements
Closed
KD
8h ago+188+188+012345678901234567890123456789-22-22-01234567890123456789
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
mouseenteropens 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-disabledwrapper around a slot inside a closed shadow root, content behind a modal). Neither does an element its ownmouseenterdisables. - 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 withACTION_FAILEDinstead 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
scrollIntoViewran on after the budget expired, while they waited for another action's input to finish.
How it works
actionablePointtakespointerFirstfor 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).Mouse.at(x, y)says whether the pointer is already at a point.click,longPress, anddragsend no move when it is (packages/electron/src/cdp/input.ts:209-220,packages/electron/src/actions.ts).heldBackreads the node's own entry in Chromium's accessibility tree (Accessibility.getPartialAXTree) and refuses one that is inert or disabled (actionability.ts:44).waitReadyuses it too.- The step's
check()callsbudget.check(). The probe calls it before it scrolls, before the fallback scroll, and before the pointer move.scrollIntoViewcalls it before each scroll it polls (actionability.ts:90-111,actions.ts). - Modifier state tracks the left and right keys, so a modifier is released only when both are up.
AltGraphreleases Alt (input.ts:94). - 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), andpnpm check. - 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 |
|---|---|---|---|
| unit | Keyboard holds a modifier while its key on the other side is still down | fails | passes |
| unit | Mouse presses where the pointer already is without moving it again | fails | passes |
| integration | a tap presses nothing that the pointer's arrival shows over its target | fails | passes |
| integration | a tap takes no tap on an element its own mouseenter disables | fails | passes |
| integration | a button disabled through a closed shadow root takes no tap, as Chromium's tree says it is disabled | fails | passes |
| testbed | tests/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 input | fails | passes |
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 YESfrom #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
mouseenterwas pressed (3ac15b228, with a test). - Fixed: the fallback scroll ran without a budget check (
ff377f96c, no test: it needsDOM.scrollIntoViewIfNeededto 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, andweb()'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.