screenshotWithAccessibilityLabels overlays color-coded labels on every interactive element. The agent sees the screenshot, reads the labels, and interacts by reference.12await screenshotWithAccessibilityLabels({ page: state.page }) // Image and accessibility snapshot are automatically included in the response
e1, e2, e3...), captures the annotated image, then removes the labels. Both the image and an accessibility snapshot are returned automatically.refToLocator to convert a visual label to a Playwright locator:123// From the screenshot, the agent sees label "e5" on a button const locator = refToLocator({ ref: 'e5' }) await state.page.locator(locator).click()
123await screenshotWithAccessibilityLabels({ page: state.page }) // Snapshot shows: role=button[name="Submit"] with ref e3 await state.page.locator('role=button[name="Submit"]').click()
| Color | Element type |
| Yellow | Links |
| Orange | Buttons |
| Coral | Inputs |
| Pink | Checkboxes |
| Peach | Sliders |
| Salmon | Menus |
| Amber | Tabs |
1234await screenshotWithAccessibilityLabels({ page: state.page }) await state.page.click('button.next') await screenshotWithAccessibilityLabels({ page: state.page }) // Both images are returned
| Parameter | Type | Default | Description |
page | Page | required | Playwright page to screenshot |
interactiveOnly | boolean | true | Only label interactive elements |
screenshotWithAccessibilityLabels for complex visual layouts where spatial position matters: grids, image galleries, maps, dashboards, canvas-based UIs.snapshot() with search. It's faster, cheaper, and uses fewer tokens.snapshot() works the same as a ref from screenshotWithAccessibilityLabels().123await state.page.screenshot({ path: '/tmp/page.png', scale: 'css' }) await resizeImageForAgent({ input: '/tmp/page.png' }) // Resized image is automatically included in the response
resizeImageForAgent accepts width, height, maxDimension, quality, and format options.