Skip to content

fix(computer-use): give web text fields real keyboard focus on macOS - #3846

Merged
bobleer merged 2 commits into
openBitFun:mainfrom
bobleer:bob/fix-computer-use-web-text-focus
Nov 9, 2026
Merged

bobleer merged 2 commits into
openBitFun:mainfrom
bobleer:bob/fix-computer-use-web-text-focus

Conversation

@bobleer

@bobleer bobleer commented Nov 9, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

On macOS, clicking a web text field by node_idx (or passing it as focus) did not give it keyboard focus, so later typing, Delete and Return were silently lost while the tool reported submitted. These controls now use a real directed click and the directed keyboard route. Native controls keep the AX path.

The same session exposed smaller observation problems, also addressed here:

  • Window images that did not change although the accessibility tree did gave no signal. The observation now starts with a WINDOW_NOT_REPAINTED note. It goes first because long trees are clipped at the end.
  • The focused text field's value was clipped at 120 characters, so a draft could not be read to the end before sending. It now keeps up to 4000.
  • Chromium reports AXExpanded = false on nearly every web node. [collapsed] is no longer rendered for structural roles, and AXScrollToVisible is no longer listed. Digests are unchanged, since they are computed from the nodes rather than the rendered text. On the 85 KB tree from the failing session this noise was up to about a third of the text.
  • The zoom region error now states the requested region and the valid bounds.

Type and Areas

Type: bug fix

Areas: Computer Use native service (macOS focus routing, shared observation note), tool contracts (error text)

Motivation / Impact

AXPress and AXFocused succeed on a text control inside an AXWebArea, but only move the page's DOM focus. The window's first responder stays where it was. In the reported Feishu/Lark session, node_idx clicks on the composer were followed by lost text, Delete and Return, and command+a selected the message list instead of the draft. The agent had to fall back to the clipboard and the send button.

Behavior of the new route:

  • Detection is role based (text roles and AXComboBox with an AXWebArea ancestor, in a bounded parent walk), so there are no application name rules.
  • A real click places the caret at the center of the field, the same as an image_xy click.
  • A later focus request on a field that a real click already focused sends no click, so command+a followed by typing with focus still replaces the selection. Other pointer or semantic input, shortcuts that can move focus, focus-loss events and Stop end that state, and the next request clicks again.
  • A field scrolled out of view returns TARGET_COORDINATES_OUTSIDE_WINDOW and sends no click. Chromium clips such a node's frame to the viewport edge, so without this the click would land on the edge.

Verification

Commands, on macOS 27.2:

  • cargo test --locked -p openbitfun-computer-use --lib: 224 passed, 10 ignored.
  • node scripts/test-computer-use-context.mjs: passed.
  • node scripts/test-macos-computer-use-self.mjs: passed (same-process AppKit and WebKit, node and image clicks, Unicode text, Stop).
  • node scripts/test-windows-computer-use-native.mjs --check --target x86_64-pc-windows-msvc: type-checks only, no Windows execution.
  • pnpm run check:repo-hygiene: passed. pnpm run check:core-boundaries passed on the first commit; the follow-up does not change Cargo manifests.

Manual reproduction through the devtools JSONL probe, on a disposable Electron window with two WebContentsViews, with the target confirmed not frontmost and results read back from the DOM over CDP:

Scenario Before After
app_click with node_idx, then text, Delete, command+a, Return all input lost, document.hasFocus() false all delivered
app_type_text with focus: node_idx not measured delivered
Click, type, command+a with focus_idx, type with focus not measured selection kept, text replaced
Click another input, type there, then type with focus on the first field not measured focus returns, text lands in the first field
Field scrolled out of view, node_idx click not measured rejected, no click sent

Not verified:

  • node scripts/test-macos-input-controls.mjs --semantic was inconclusive: it exited with its 3-second input-idle gate unmet because the machine was in use, so no case ran.
  • The real Feishu/Lark app. The fixture reproduces the same failure, but no personal application window was used for testing.
  • Chrome on the node_idx route (its web nodes were not exposed during the fixture run).
  • Whether earlier macOS releases behave differently. Only 27.2 was available.
  • Windows and Linux at runtime. The focus change is macOS only; the shared code only adds the repaint note.
  • Remote workspace, remote control, Peer Device Mode and Detached Dispatch. All testing was local.

Reviewer Notes

  • No wire or persisted format changes. The note is part of tree_text, as CAPTURE_UNAVAILABLE already is.
  • Known limit: web content covering the center of a visible field cannot be detected. Chromium's synchronous AX hit test ignores stacking (tested with a button over the field: it returned the field and the button took the click). A hit-test guard was tried and removed for that reason. An image_xy click behaves the same way.
  • A key-event authentication hypothesis (passing the real PID version to the SkyLight message) was tested and ruled out: delivery was identical with both values, so it is not included.
  • The occluded case matches the note: a fully covered Electron window reported visibilityState: hidden and exposed no web nodes until occlusion handling was disabled for the fixture.

AI-assisted. Testing level: lightly tested.

Checklist

  • This PR is focused and does not include secrets, temporary prompts, generated scratch files, or unrelated artifacts.
  • Relevant verification is recorded above, or skipped checks are explained.
  • User-facing strings, docs, and locales are updated where applicable.

AXPress and AXFocused on a text control inside an AXWebArea succeed but
only move the page's DOM focus. The window's first responder stays where
it was, so later directed text, Delete and Return are lost while the tool
reports them as submitted. Route node targets and the focus parameter for
these controls through the directed click and keyboard path; native
controls keep the AX path.

Report when the window image is byte-identical to the previous observation
although the accessibility tree changed, keep the full value of the focused
text field so a draft can be read to the end, stop rendering Chromium's
AXExpanded noise on structural nodes and AXScrollToVisible, and include the
valid bounds in the zoom region error.
A real click on every focus request collapsed the selection and moved the
caret. Remember the field a real click focused and send no further click
while its focus is known to hold; other pointer or semantic input,
shortcuts that can move focus and focus-loss events end that state.

Report a web text field scrolled out of view instead of clicking the
viewport edge, include web comboboxes in the route, and put the repaint
note first because long trees are clipped at the end.
@bobleer
bobleer merged commit 8f2ff58 into openBitFun:main Nov 9, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant