Skip to content

MCP act focus by ref fails unless the DOM document was requested first #2640

Description

Problem

The Rust MCP contract suite currently documents a live limitation:

act with kind: "focus" and a DOM ref fails instead of focusing the referenced element.

The contract case is named act: focus by ref reports the current DOM-domain limitation in packages/browseros-agent/contracts/claw-mcp/tests/cases-act.ts.

While debugging PR #2583, the same underlying path surfaced in CI as:

act failed: CDP error: Document needs to be requested first

That error came from the core focus path:

  • packages/browseros-agent/crates/browseros-core/src/input/geometry.rs
  • focus_element() calls DOM.pushNodesByBackendIdsToFrontend
  • then calls DOM.focus

In the BrowserOS CI browser, DOM.pushNodesByBackendIdsToFrontend can fail unless the DOM document has first been requested for that session.

Impact

Agents can click/fill/type referenced elements, but cannot reliably call the explicit focus action by ref. This also makes future ref-targeted keyboard behavior easy to regress, because focusing via the DOM domain is not usable in every session state.

Expected behavior

act { kind: "focus", ref } should focus the referenced element successfully, or core should use a focus implementation that does not require prior DOM.getDocument state for the session.

Possible fix

Use the runtime/object path already used by other semantic ref actions:

  1. Resolve the backend node with DOM.resolveNode.
  2. Call Runtime.callFunctionOn with this.focus().
  3. Keep the existing DOM-domain DOM.focus path only if there is a reason it is preferred after DOM.getDocument.

PR #2583 added a runtime focus path for press(ref) because it hit this limitation; the standalone focus action still uses the brittle DOM-domain path.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions