Server Configuration
Describes the environment variables required to run the server.
| Name | Required | Description | Default |
|---|---|---|---|
| browser | No | Browser to use: chromium, firefox, webkit (default: chromium) | chromium |
| headless | No | Run browser in headless mode (default: false) | false |
| cdp-endpoint | No | Connect to existing browser via CDP endpoint | |
| user-data-dir | No | Use persistent browser profile directory |
Capabilities
Features and capabilities supported by this server
| Capability | Details |
|---|---|
| tools | {} |
| resources | {} |
Tools
Functions exposed to the LLM to take actions
| Name | Description |
|---|---|
| snapshot | Get compressed accessibility snapshot with ref IDs. Returns: DOM tree with [ref=e1], [ref=e2] etc. Use refs with execute tool: await $('e1').click() Call again after navigation (refs become stale). Options:
|
| screenshot | Capture page screenshot. Options:
When withLabels is used, labels are color-coded by role:
|
| browser_execute | Execute Playwright code with these in scope:
Rules
Checking Page StateAfter any action (click, submit, navigate), verify what happened: console.log('url:', page.url()); console.log(await accessibilitySnapshot().then(x => x.split('\n').slice(0, 30).join('\n'))); For visually complex pages (grids, galleries, dashboards), use screenshotWithAccessibilityLabels({ page }) instead. Accessibility Snapshotsawait accessibilitySnapshot() // Full snapshot
await accessibilitySnapshot({ search: /button|submit/i }) // Filter results
await accessibilitySnapshot({ showDiffSinceLastCall: true }) // Show changes Example output: - banner [ref=e3]:
- link "Home" [ref=e5] [cursor=pointer]:
- /url: /
- navigation [ref=e12]:
- link "Docs" [ref=e13] [cursor=pointer] Use aria-ref to interact - NO quotes around the ref value: await page.locator('aria-ref=e13').click() // or: await $('e13').click() For pagination: Choosing snapshot method:
Selector Best PracticesFor unknown sites: use accessibilitySnapshot() with aria-ref For development (with source access), prefer:
If locator matches multiple elements (strict mode violation), use await page.locator('button').first().click()
await page.locator('li').nth(3).click() // 4th item (0-indexed) Working with Pagesconst pages = context.pages().filter(x => x.url().includes('localhost'));
state.newPage = await context.newPage(); await state.newPage.goto('https://example.com'); Navigationawait page.goto('https://example.com', { waitUntil: 'domcontentloaded' });
await waitForPageLoad({ page, timeout: 5000 }); Common PatternsPopups: page.evaluateCode inside page.evaluate() runs in the browser - use plain JavaScript only. console.log inside evaluate runs in browser, not visible here: const title = await page.evaluate(() => document.title);
console.log('Title:', title); // Log outside evaluate Utility Functions
Network InterceptionFor scraping/reverse-engineering APIs, intercept network instead of scrolling DOM: state.requests = []; state.responses = [];
page.on('request', req => { if (req.url().includes('/api/')) state.requests.push({ url: req.url(), method: req.method(), headers: req.headers() }); });
page.on('response', async res => { if (res.url().includes('/api/')) { try { state.responses.push({ url: res.url(), status: res.status(), body: await res.json() }); } catch {} } }); Then trigger actions and analyze: IMPORTANT: After navigation, refs are stale - call snapshot tool again. |
| browser_search_snapshot | Search current snapshot with regex. Requires: Call snapshot first. Returns: Matching lines with refs. Options:
Use this to find specific elements in large pages without re-reading the entire snapshot. |
| browser_network_requests | Get captured network requests from the browser. Automatically starts capturing when first called. Use includeStatic:true to include images/CSS/fonts. Returns recent requests with status, timing, and response previews. |
Prompts
Interactive templates invoked by user choice
| Name | Description |
|---|---|
No prompts | |
Resources
Contextual data attached and managed by the client
| Name | Description |
|---|---|
| Debugger API | CDP Debugger API - set breakpoints, step through code, inspect variables |
| Editor API | CDP Editor API - view and live-edit page scripts and CSS at runtime |
| Styles API | CDP Styles API - inspect CSS styles applied to elements |