Files
abbbce71c0 fix(electron): share held input across windows and tighten launch checks (#2472)
* fix(electron): share held input across windows and tighten launch checks

* test(electron): send the cross-window wheel before the text edit

On Linux under xvfb, Chromium can drop a synthetic wheel event sent right
after a text edit in a hidden window, with or without held input, so the
held-input integration test failed in CI's electron job. Sending the wheel
before the edit keeps the check on what the event carries.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(electron): refuse owned switches spelled with / on Windows

Chromium reads `/` as a switch prefix on Windows, so `/user-data-dir=...`
got past ownedArgument there. On Windows the check now reads a leading
`/` as a dash; elsewhere `/...` stays a path. The callers pass only the
argument, so `.map` cannot hand the index in as the platform.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(electron): keep a newer press's button when an older press rejects

A rejected mouse down restored the shared lastButton to the value it saw
before its send, so a press another window made in between lost its
button: later moves sent `button: none` with `buttons` set. The rollback
now undoes only this press's own write, and only to a button still held.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* docs(electron): say that pressing a held key releases it in every window

One keyboard serves every window, so `keyboard.press()` on a key another
window holds releases that hold, as it did on a single page before. The
keyboard reference says so and a unit test pins it across two windows.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* docs(electron): name the wheel buttons and the switch spellings in the changeset

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(electron): start the hung chord once the window is busy, not after 30 ms

The blocking script now logs a marker right before its busy loop and the
chord starts when that console message arrives, so the press always meets
a busy renderer however slow the runner is.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(electron): pin that window.reload() does not get past a beforeunload guard

The reference says a guard that cancels the unload is not bypassed. Electron
cancels such an unload without a JavaScript dialog unless the app handles
will-prevent-unload, so the engine's dialog handler never accepts it. The
test keeps the document and its globals through a reload attempt; without
the guard the reload resolves and the test fails.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(electron): keep the cross-platform pass list free of a Windows switch

58235a3ad made `/inspect` an owned switch on Windows, but an existing
assertion passed it through checkLaunchOptions on every platform, so the
unit tests failed on Windows. The win32 and linux assertions on
ownedArgument cover `/` already.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(electron): keep a newer press's button when an older release rejects

A rejected mouse up put the shared lastButton back to the button it saw
before its send, even after another window pressed a different button in
between, so later moves reported the older button. Like the rejected press,
it now restores only when nothing pressed since it cleared the value.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* docs(electron): say up() releases a hold whichever window is active

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* docs(electron): say that a click with a held button releases it in every window

One mouse serves every window, so a tap, or another action that clicks,
with a button another window holds releases that hold, as a click did on
a single page before. The mouse reference says so and a unit test pins
it across two windows. Its control clicks the other button: the held
button stays in the buttons mask and later moves report button none, as
after releasing one of two held buttons on one page.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

* refactor(electron): require the launch's held input on Keyboard and Mouse

Keyboard and Mouse defaulted their shared HeldInput to a new one, so a
caller that left it out would hold keys and buttons for its own window
only, which is what sharing them across windows set out to end. Only
tests used the default: PageTarget, their one caller in src, passes its
own. The parameter is now required and the tests pass one. A unit test
builds each without it: the typecheck refuses that, and the first use
rejects instead of holding input for one window.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

* fix(electron): commit a held key or button release before its event is sent

A release whose send failed on a closing window put the hold back from saved
owners, guarded by a release number. Two releases in flight (one double click
on a closing window, or two key-ups on two closing windows) left the older one
superseded and the newer one with nothing to restore, so a hold another
window still had was dropped, while a single failed click kept it.

A release now clears the hold before its event is sent, as main does in one
window, and never restores it: a failed tap releases the other window's hold
the way a landed tap does, and the step still fails as
ACTION_MAY_HAVE_COMMITTED. restoreOwners, the release numbers, and the owner
generations go; owners are a Set per key.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(electron): release a held button at a long press or drag's release, as a tap does

After electron.mouse.down(), a longPress or dragTo in any window released
only its own press, so the next move still reported the button held, where
main reported it released in one window and a tap releases it in any
window. A gesture's release now also releases the held button.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(electron): keep Shift while another Shift key is held, and clear both by name

Modifiers were tracked by name: ShiftLeft going up in one window cleared the
Shift a ShiftRight held in another window gave, and up('Shift') after
down('ShiftRight') left the ShiftRight code held, so its next press was sent
as an auto-repeat. A sided release now keeps a modifier while another key of
it is held, with the owners of those keys; releasing the plain name still
releases both sides, as main and Playwright do.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(electron): run overlapping chords while another window holds Shift

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(electron): give the three-window readiness poll ten seconds

The held-input integration test polled for its three windows with
expect.poll's default of one second. The fixture app loads the windows
one after another and launch() can return after the first, so a loaded
host can miss that second before any input assertion runs. The poll now
takes the 10 s that the other slow window-count poll in this file has.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

* test(electron): cover a closed or rejected key holder and a gesture's own button

Three lines of the shared held input had no test that fails without
them: Keyboard.reset() dropping a closed window as holder of a plain
key, the rollback of a rejected shared key press, and Mouse.move()
naming a gesture's own button. The first two show as autoRepeat on the
next press of that key in another window, the third as the button field
of a move while the test holds a different button. A key that a second
window still holds must stay a repeat, so forgetting the key for every
window fails the test too.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

* fix(electron): roll back only a failed press's own last-button write

A shared mouse.down() that rejects on a closing window rolled the shared
last button back only when the failed button was held nowhere else, a
guess at "no newer press". When another window still held that button,
the guess kept the failed press's write: with left and right held in
window A, a rejected down('left') in window B left the last button on
left, so A's next move sent button 'left' where main sent 'right'.

HeldInput now numbers every write to the last button behind one setter,
and a failed press rolls back only when no press or release wrote after
it, to the previous button if it is still held. A newer press of the
same button and a newer release both keep their own write.

Reported by kdy1 on #2472.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(electron): refuse owned switches behind U+0085 on Windows

ownedArgument() trimmed an argument with String.prototype.trim(), which
keeps U+0085 (NEXT LINE). Chromium's Windows command line parser trims
it before it looks for a switch, so on Windows an argument such as
U+0085 followed by --user-data-dir=... passed the check and could set
the profile directory the engine owns. The Windows branch now trims
U+0085 with the whitespace trim() knows. Elsewhere Chromium trims ASCII
whitespace only, so such an argument is no switch and still passes.

Reported by KrzysztofMoch on #2472.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(electron): pin the rollback of a rejected press against three untested rules

The test titled "keeps a newer press of the same button" pressed a
different button, so a rollback guarded by the button name alone
passed it. It now presses the same button the rejected press used.
Two new tests cover a rollback to none when a closed window let go of
the previous last button, and a failed repeated press that keeps the
window's own earlier hold.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: michal-e2e <357875193+michal-e2e@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 16:11:18 +00:00
..
2026-12-02 14:25:52 +01:00
2026-12-02 14:25:52 +01:00

@e2e-dev/electron

The Electron engine for e2e: an Electron app's windows, read through Chromium's accessibility tree over the DevTools protocol and driven with trusted input, through the same @e2e-dev/core/engine contract the browser, mobile, and desktop engines implement. A test written against screen, expect, app, and agent runs on an Electron target unchanged.

Note

Electron support is experimental. The electron() options, the electron fixture, and how the engine behaves can change in any release, including a patch, until it's stable. Pin @e2e-dev/electron to an exact version in package.json, with no ^, and read the release notes before you upgrade.

It is also the reference for an engine built outside this repository: it imports only @e2e-dev/core/engine and speaks the DevTools protocol itself, with no automation library and never another engine.

Install

npm install --save-dev e2e @e2e-dev/electron electron

The engine starts the electron package installed in the project, and downloads its binary one time per run when it is missing. Run npx e2e doctor to check.

import type { E2EConfig } from 'e2e';
import { electron } from '@e2e-dev/electron';

export default {
  targets: [{ name: 'electron', engine: electron(), app: { appPath: '.' } }],
} satisfies E2EConfig;

app.appPath is the app's directory or main script, and app.launchArguments are the switches every launch gets, the app's own and Chromium's. For a packaged app, pass electron({ executablePath }) and leave out appPath.

import { test } from '@e2e-dev/electron';
import { credentials, expect } from 'e2e';

test('signs in', async ({ app, screen }) => {
  await app.open();
  await screen.getByRole('textbox', 'Username').fill('ada');
  await screen.getByRole('textbox', 'Password').fill(credentials.user('ada').password);
  await screen.getByRole('button', 'Sign in').tap();
  await expect(screen.getByTestId('status')).toContainText('Signed in');
});

How it works

  • Launch. app.open() starts the app on an empty user-data directory and waits for a window to load. Every test ends with the app quit.
  • Read. Chromium's accessibility tree joined with one DOM snapshot. Nothing runs in the app's page to read it.
  • Act. Trusted mouse and keyboard input, once the node is enabled, on screen, and topmost at its point.
  • Windows. The agent sees them as tabs. The electron fixture has launch (per-test arguments and environment), userDataDir, evaluate (main process), windows, activeWindow, waitForWindow, window, waitForDownload, onDialog, locator (CSS), keyboard, mouse, and waitForURL. A window has evaluate (its page) and reload. expect(electron) asserts the active window's URL and title, and an element's class.
  • Video. The shown window's screencast, encoded to one .webm by ffmpeg, which the engine downloads on the first recording when the machine has none.
  • Secrets. Password fields report no value, and screenshots paint them and nested documents over.

Limits

Not on Electron, because the platform has no such thing:

What Instead
prompt() Electron does not implement it. Build the prompt in the page
Headless mode On Linux CI, run under a virtual display such as xvfb-run
Menu accelerators from key presses Call the menu item from electron.evaluate

Not supported yet:

What Until then
Content inside an iframe or webview A webview guest is listed as a window: electron.window()
Routes and cookies session.defaultSession in electron.evaluate
Session save and restore

The Electron guide lists every difference from the web.

License

Apache-2.0