Function Signature
Parameters
page
Type:Page (optional)
Default: Current default page
Target page to snapshot. If not provided, uses the default page from context.
frame
Type:Frame | FrameLocator (optional)
Optional frame to scope the snapshot. Use for iframe content:
locator
Type:Locator (optional)
Scope snapshot to a specific element subtree. Dramatically reduces output size when you only care about one section:
search
Type:string | RegExp (optional)
Filter results to first 10 matching lines with 5 lines of context:
search is provided, showDiffSinceLastCall defaults to false so search filters the full content.
showDiffSinceLastCall
Type:boolean (optional)
Default: true (unless search is provided, then false)
Return diff since last snapshot call. First call returns full snapshot, subsequent calls return only changes:
"No changes since last snapshot. Use showDiffSinceLastCall: false to see full content."
To combine search with diff, explicitly enable both:
format
Type:'raw' (optional)
Default: 'raw'
Snapshot format. Currently only 'raw' is supported.
interactiveOnly
Type:boolean (optional)
Default: false
Only include interactive elements in the snapshot. When true, filters to buttons, links, inputs, and other interactive roles.
Return Value
Type:Promise<string>
Returns a text-based accessibility tree with locators:
>> nth=N suffix is added (0-based):
Examples
Basic usage
With locators
Tracking changes
Using with frames
Notes
- Always use snapshot locators directly — never invent selectors. The snapshot output IS the selector.
- Snapshots are text-based, fast, and cheap. Use them as your primary debugging tool.
- Only use screenshots for visual/CSS issues. For text content, snapshot is much faster.
- Beware CSS text-transform: snapshots show visual text (
heading "NODE.JS") but DOM may be"Node.js". Use case-insensitive regex:getByRole('heading', { name: /node\.js/i })
Backward Compatibility
accessibilitySnapshot is still available as an alias for backward compatibility: