feat(electron): read windows with the shared in-page reader

OK
6h ago
+1781-2272

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
SurfaceBeforeAfter
electron: role set via ElementInternalsreadnot read (same on web and bidi)
electron: observation cap5,000 nodes3,000, as web
electron: display: none checkbox or radio drawn by its labelshownhidden, as web; one with no size is still shown
electron: locator in a window with more than 50,000 elementsresolvedfails, since the read is partial
electron: bare text node beside sibling elementsmatched by getByTextnot a match of its own
electron: node idsserial.generation.backendNodeIdserial.generation.n<id>
electron: page's main worlduntouchedtwo init scripts (closed shadow roots, modal order)
bidi + electron: <h2 aria-level="4"> in a role querylevel 4 on bidilevel 2, as web
bidi + electron: level on list item, row, tree itemno match on bidimatches aria-level, as web
bidi: box-less checkbox drawn by its labelrole query finds nothingfound, 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, ElementInternals roles, the modal-order script on bidi.

How it works

Flow and files
  • One Runtime.evaluate runs 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() and bidi() 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/**/*.mdx page for the behavior, and skills/e2e/ if the skill describes it.
  • Contract change: emitted .d.ts reviewed, tests/types/sdk-types.ts updated; wire change edits the schema and both fixtures.
  • Engine contract change (e2e/engine): changesets for e2e, @e2e-dev/web, and @e2e-dev/mobile.