Function Signature
Parameters
page
Type:Page (required)
The page to screenshot.
interactiveOnly
Type:boolean (optional)
Default: true
Only show labels for interactive elements (buttons, links, inputs, etc.). When false, shows labels for all elements including text nodes.
Return Value
Type:Promise<void>
The function doesn’t return a value. Instead, it automatically adds the screenshot and accessibility snapshot to the execution result.
Output
After calling this function, the execution result includes:- Screenshot file saved to
./tmp/playwriter-screenshot-{timestamp}-{random}.jpg - Base64 image data automatically included in the response
- Accessibility snapshot showing all labeled elements with their locators
- Label count showing how many elements were labeled
Label Appearance
Labels are color-coded by element type:- Yellow — Links
- Orange — Buttons
- Coral — Text inputs
- Pink — Checkboxes
- Peach — Sliders
- Salmon — Menus
- Amber — Tabs
e1, e2, or stable IDs like submit-btn).
Examples
Basic usage
Multiple screenshots
With all elements
When to Use
UsescreenshotWithAccessibilityLabels when:
- Page has complex visual layout (grids, galleries, dashboards, maps)
- Spatial position matters (e.g., “first image”, “top-left button”)
- DOM order doesn’t match visual order
- You need to understand the visual hierarchy
- You just need text content → use
snapshot({ search: /pattern/ })instead - Checking if an element exists → use
snapshot()instead - Reading console logs → use
getLatestLogs()instead - Verifying text appeared → use
snapshot()instead
Timeout
Use a timeout of 20 seconds for complex pages:Combining with snapshot()
Prefer this workflow:- Use
screenshotWithAccessibilityLabelsfirst to understand layout and identify target elements visually - Then use
snapshot({ search: /pattern/ })for efficient searching in subsequent calls
Using refs from screenshot
The snapshot shows refs likee1, e2, etc. Use refToLocator() to convert them to selectors:
Notes
- Labels auto-hide after screenshot is taken
- Labels are repositioned if page layout changes
- Use
scale: 'css'for regular screenshots to avoid 2-4x larger images on high-DPI displays - Screenshot is automatically resized to optimal dimensions for Claude vision (1568px max)
- If sharp is not installed, screenshots are clipped to 1568px instead of resized