feat(electron): read windows with the shared in-page reader
OK
6h ago+1781+1781+0123456789012345678901234567890123456789-2272-2272-0123456789012345678901234567890123456789
Why
web() and bidi() read a page with one reader (@e2e-dev/dom). electron() still projected Chromium's accessibility tree on the host, so the same page read differently there: on the fixture pages its tree differed from web's in 826 places. This PR moves electron() to the shared reader, which leaves only frames as a difference. Builds on #2692.
What
No API change. Changes for existing users of electron():
- Roles and names follow web's rules, not Chromium's accessibility tree.
- A text query answers with the element holding the text, not the control around it.
- A locator finds content behind a modal dialog; acting on it is still refused.
All behavior changes
| Surface | Before | After |
|---|---|---|
electron: role set via ElementInternals | read | not read (same on web and bidi) |
| electron: observation cap | 5,000 nodes | 3,000, as web |
electron: display: none checkbox or radio drawn by its label | shown | hidden, as web; one with no size is still shown |
| electron: locator in a window with more than 50,000 elements | resolved | fails, since the read is partial |
| electron: bare text node beside sibling elements | matched by getByText | not a match of its own |
| electron: node ids | serial.generation.backendNodeId | serial.generation.n<id> |
| electron: page's main world | untouched | two init scripts (closed shadow roots, modal order) |
bidi + electron: <h2 aria-level="4"> in a role query | level 4 on bidi | level 2, as web |
bidi + electron: level on list item, row, tree item | no match on bidi | matches aria-level, as web |
| bidi: box-less checkbox drawn by its label | role query finds nothing | found, as the observation lists it |
Trade-offs
- Chose the page's main world, not the isolated one. The reader needs the closed shadow roots and modal order recorded there; the cost is two small scripts in the app's page, and that a page script can reach a recorded closed root while under test, as on
web(). - Chose to hold each new window until the scripts are registered. A closed shadow root its first document attaches is then always entered; the cost is that a window starts a few milliseconds later. A window the app opens while it starts can already be running when the engine attaches and is not held, so there such a root is entered only if the attach won the race (it lost on Windows CI).
- A crashed renderer is reported later on Linux with a core dump handler. Measured on CI (
systemd-coredump): 0.5 s before, 1.45 s once the reader ran in the page, 13 ms with no handler, on main and here alike. The crash test waited 1 s and now waits up to 5 s. - Not in this PR: reading into iframes on electron,
ElementInternalsroles, the modal-order script on bidi.
How it works
Flow and files
- One
Runtime.evaluateruns the reader and the expression's selectors, answering one JSON string.packages/electron/src/devtools.ts - The host builds the tree with dom's
assembleTree; locate resolves with core's resolver.packages/electron/src/locate.ts - An action resolves a node id to a backend node id on demand (
backendNodeOf).packages/electron/src/devtools.ts - A new window is held (
waitForDebuggerOnStart) until the reader's init scripts are registered.packages/electron/src/app-process.ts - The init scripts moved from web to dom.
packages/dom/src/document-scripts.ts - Electron is an intake of the golden observations; its 25 listed differences are all frames.
apps/dom-conformance/src/electron-intake.ts
Issue
None.
Verified
Ran it locally: yes
- Electron testbed through the built CLI: 105 of 105 pass, after four assertions moved to what web does on the same page.
- Golden observations: electron differs from web only in frames it does not enter.
- I ran the six assertions that first failed on
web()andbidi()against the same page to decide which were parity and which were reader gaps (level, label-drawn checkbox); the gaps are fixed in the reader. - Not run:
pnpm bench:ab. An earlier measurement on the fixture pages had the in-page read faster on larger pages and about 1 ms slower on tiny ones. - Not run in CI: the bidi testbed. Locally it fails the same 37 tests with and without the reader change.
Commands and output
At the head commit, macOS:
$ cd apps/electron-testbed && node node_modules/e2e/dist/cli/bin.js run
Tests 105 passed (105)
$ pnpm --filter @e2e-dev/electron test Tests 161 passed (161)
$ pnpm --filter @e2e-dev/electron run test:integration Tests 130 passed (130)
$ pnpm run test:dom Tests 136 passed | 1 skipped (137)
$ pnpm --filter @e2e-dev/bidi test Tests 206 passed (206)
$ pnpm run test:web Tests 1345 passed | 2 skipped (1347)
$ pnpm check exit 0
test:web failed once on network.test.ts (Firefox service worker, 30 s timeout) and passed on rerun and in isolation.
Checklist
- Changeset added (
pnpm changeset) for any change to a published package, or the change is testbed, docs, or CI only. - Breaking change: title carries
!, the changeset body names what breaks and what replaces it, and the deprecation warning landed a window earlier (stability policy in CONTRIBUTING.md). - Docs updated in the same PR: the
docs/**/*.mdxpage for the behavior, andskills/e2e/if the skill describes it. - Contract change: emitted
.d.tsreviewed,tests/types/sdk-types.tsupdated; wire change edits the schema and both fixtures. - Engine contract change (
e2e/engine): changesets fore2e,@e2e-dev/web, and@e2e-dev/mobile.