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
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
@e1- At-prefixed refref=e1- Ref with equalse1- Direct ref (pattern: /^e\d+$/)
getSnapshotStats()
Get statistics about a snapshot.string
Snapshot tree text
RefMap
Snapshot refs map
object
resetRefs()
Reset the ref counter. Called automatically at the start of each snapshot.Types & Interfaces
EnhancedSnapshot
The result ofgetEnhancedSnapshot().
RefMap
Map of element refs to their locator data.SnapshotOptions
Configuration options forgetEnhancedSnapshot().
Interactive Roles
Elements with these ARIA roles are considered interactive and receive refs:buttonlinktextboxcheckboxradiocomboboxlistboxmenuitem,menuitemcheckbox,menuitemradiooptionsearchboxsliderspinbuttonswitchtabtreeitem
Content Roles
Elements with these roles get refs for text extraction:headingcell,gridcell,columnheader,rowheaderlistitemarticleregionmainnavigation
Cursor-Interactive Elements
Whencursor: true is enabled, the snapshot includes elements with:
cursor: pointerCSS propertyonclickattribute or handlertabindexattribute (except-1)
clickable- Has cursor:pointer or onclickfocusable- Has tabindex
Usage with BrowserManager
TheBrowserManager class provides a convenient wrapper: