Skip to main content

Snapshot Functions

The snapshot module provides functions for generating accessibility tree snapshots with embedded element refs for deterministic element selection.

Core Functions

getEnhancedSnapshot()

Generate an enhanced accessibility snapshot with element refs.
Page
Playwright Page instance
SnapshotOptions
Snapshot configuration options
boolean
Only include interactive elements (buttons, links, inputs, etc.)
boolean
Include cursor-interactive elements (cursor:pointer, onclick, tabindex)
number
Maximum depth of tree to include (0 = root only)
boolean
Remove structural elements without meaningful content
string
CSS selector to scope the snapshot to a specific element
EnhancedSnapshot
string
Accessibility tree as formatted text with refs
RefMap
Map of element refs (e1, e2, etc.) to locator data
Example Output:

parseRef()

Parse a ref from a command argument. Supports multiple ref formats.
string
Ref argument string (e.g., ‘@e1’, ‘ref=e1’, or ‘e1’)
string | null
Parsed ref ID (e.g., ‘e1’) or null if not a valid ref format
Supported Formats:
  • @e1 - At-prefixed ref
  • ref=e1 - Ref with equals
  • e1 - Direct ref (pattern: /^e\d+$/)

getSnapshotStats()

Get statistics about a snapshot.
string
Snapshot tree text
RefMap
Snapshot refs map
object
number
Number of lines in tree
number
Number of characters
number
Estimated token count (chars / 4)
number
Total number of refs
number
Number of interactive element refs

resetRefs()

Reset the ref counter. Called automatically at the start of each snapshot.

Types & Interfaces

EnhancedSnapshot

The result of getEnhancedSnapshot().

RefMap

Map of element refs to their locator data.
Example:

SnapshotOptions

Configuration options for getEnhancedSnapshot().

Interactive Roles

Elements with these ARIA roles are considered interactive and receive refs:
  • button
  • link
  • textbox
  • checkbox
  • radio
  • combobox
  • listbox
  • menuitem, menuitemcheckbox, menuitemradio
  • option
  • searchbox
  • slider
  • spinbutton
  • switch
  • tab
  • treeitem

Content Roles

Elements with these roles get refs for text extraction:
  • heading
  • cell, gridcell, columnheader, rowheader
  • listitem
  • article
  • region
  • main
  • navigation

Cursor-Interactive Elements

When cursor: true is enabled, the snapshot includes elements with:
  • cursor: pointer CSS property
  • onclick attribute or handler
  • tabindex attribute (except -1)
These elements get pseudo-roles:
  • clickable - Has cursor:pointer or onclick
  • focusable - Has tabindex
The selector for cursor-interactive elements is a CSS selector, not a role-based selector.

Usage with BrowserManager

The BrowserManager class provides a convenient wrapper: