Skip to main content
Construct with [AccessibilitySnapshot.fromNode] (e.g. from [Machine.focusedRoot]) or [AccessibilitySnapshot.fromWindow]. Render it as LLM-facing text with [AccessibilitySnapshot.toStringWith], resolve indices back to live nodes with [AccessibilitySnapshot.node], and act on elements by index via the action methods. Indices are frozen at capture time and cover every node of the walk (including collapsible wrappers), so the same snapshot can be printed with different [SnapshotPrintOptions] without renumbering. A consequence: rendering with collapseStructural produces non-contiguous [ref=N] values, because skipped wrappers keep their index.

Constructor

Returns

AccessibilitySnapshot

Properties

number
required
Number of captured nodes. Alias for [AccessibilitySnapshot.len].

Methods

activate()

Invoke / press the element at index.

Parameters

number
required

boundingBox()

Live bounding box of the element at index — for example for a coordinate-click fallback when a semantic action fails.

Parameters

number
required

Returns

BoundingBox

click()

Click the element at index, dispatching to the platform action that matches its current role:
  • button / link / menuitem / img → activate
  • tab / radio / option → select
  • combobox / treeitem → expandCollapse
  • checkbox / switch → toggle
  • anything else → activate
On error, callers can fall back to a coordinate click at the centre of [AccessibilitySnapshot.boundingBox].

Parameters

number
required

clickablePoint()

A screen point where a pointer click actually lands on the element at index, as [x, y] in the canonical global-desktop space. Verified by hit-testing; throws (saying why) when the element has no such point, instead of guessing a center that would click something else. See [AccessibilityNode.clickablePoint] for the per-platform behavior and the allowDescendants semantics.

Parameters

number
required
null | boolean

Returns

[number, number]

expandCollapse()

Expand or collapse the element at index.

Parameters

number
required

focusElement()

Alias for [AccessibilitySnapshot.setFocus].

Parameters

number
required

fromNode()

Construct a snapshot of the subtree rooted at node. This is a full pre-order walk with no structural collapse and no property reads. Filtering and formatting are deferred to [AccessibilitySnapshot.toStringWith] so one capture can serve several renderings.

Parameters

AccessibilityNode
required

Returns

AccessibilitySnapshot

fromWindow()

Construct a snapshot of window’s accessibility subtree.

Parameters

Window
required

Returns

AccessibilitySnapshot

getBounds()

Alias for [AccessibilitySnapshot.boundingBox].

Parameters

number
required

Returns

BoundingBox

isEmpty()

true if the snapshot holds no nodes.

Returns

boolean

len()

Number of captured nodes.

Returns

number

node()

Live node handle for a ref index. An out-of-range index is an error, not an expected miss: refs come from this snapshot’s own rendered output, so an unknown index means the caller mixed up snapshots (or hallucinated a ref).

Parameters

number
required

Returns

AccessibilityNode

print()

Alias for [AccessibilitySnapshot.toStringWith].

Parameters

null | SnapshotPrintOptions

Returns

string

scrollIntoView()

Scroll the element at index into view.

Parameters

number
required

select()

Select the tab / radio / list item at index.

Parameters

number
required

setFocus()

Focus the element at index (may also bring its window to the foreground).

Parameters

number
required

setValue()

Set the text value of the element at index.

Parameters

number
required
string
required

showMenu()

Open the context menu of the element at index — the semantic equivalent of a right-click, without synthesizing pointer input, so it works on background / obscured windows (Windows ShowContextMenu, macOS AXShowMenu, Linux AT-SPI show-menu, Android long-press). The opened menu itself typically appears as the topmost / focused window even when the target window stays in the background — a user watching the desktop sees a menu pop up without having done anything. Throws when the element does not support opening a menu this way; callers can fall back to a coordinate right-click at the centre of [AccessibilitySnapshot.boundingBox].

Parameters

number
required

toggle()

Toggle the checkbox / switch at index.

Parameters

number
required

toStringWith()

Render the snapshot as indented, Playwright-style lines with [ref=N] markers:
One line per rendered node: two spaces of indentation per depth level, the cross-platform ARIA role, the name (escaped and truncated per maxChars), a #automation-id marker when the platform reports one, the ref index, and a : "value" suffix for value-bearing roles. Filtering is controlled by [SnapshotPrintOptions]; returns "(empty)" when every node is filtered out. Properties are read from the live elements on every call, so the text reflects current UI state while ref numbering stays frozen.

Parameters

null | SnapshotPrintOptions

Returns

string