fix(mobile): stop reading every element of an iOS web page as focused

Closed
KA
3d ago
+102-17

What

  • On iOS, elements of a page in a WebView no longer all read as focused while no field on the page has focus. Once a field takes the keyboard, it is the only focused node, as before.

Why

  • XCTest reports focused on every element of the page, siblings included, while the page holds the focus. So not.toBeFocused() failed on a button nobody touched, the model saw every web element as focused, and the keyboard-cover check skipped them all.

How it works

  1. pageFocusEchoes (packages/mobile/src/nodes.ts:797) counts the focused elements under each outermost web view, leaving out the web view nodes (Android marks the host focused beside its field). More than one means the focus is the page's, and projectSnapshot drops the flag from all of them (nodes.ts:696).

Issue

Fixes #2331

Verified

Ran it locally: yes, iPhone 17 Pro simulator on iOS 26.5, apps/mobile-benchmark, with focus assertions added to the WebView test (tests/flows-lists.e2e.ts).

mainthis PR
ASSERTION_FAILED: expect.not.toBeFocused failed on getByRole("button", name: "Apply coupon"), observed: states: focusedpasses; after fill, the coupon field is the only focused node
  • The agentic WebView scenario still replays from its committed recording (CI=1, 1 replayed). The iOS golden tree loses only its spurious [focused] marks.

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.

Summary by CodeRabbit

  • Bug Fixes

    • Improved focus reporting in iOS web views. When no page element is focused, coupon-form elements are no longer all shown as focused; a genuinely focused field continues to be identified correctly.
    • Focus checks now better reflect the screen’s reported state across iOS and Android web views and native elements.
  • Documentation

    • Clarified that focus checks correspond to the model’s view of which element is focused.