The Complete Production SOP: How to Deploy and Run Web Browser Agent Accessibility Tree & Actions in Autonomous AI Agents
Step-by-step SOP to install and run browser-agent-dom-action-tree in Codex, Claude Code, and Cursor. Prune DOM trees and automate clicks deterministically.
Technical Overview & Architectural Context
Autonomous browser agents frequently fail in modern web applications when supplied with raw HTML or full CSS selector trees. Raw DOM dumps quickly bloat the agent's context window with thousands of non-semantic tags, SVG paths, tracking pixels, and deeply nested container divs. This token bloat creates hallucinated selectors, induces agent confusion over invisible or disabled elements, and leads to fragile XPath generation that breaks on hydration or minor CSS updates. The browser-agent-dom-action-tree skill forces the agent to interact strictly through an accessibility (a11y) tree layer augmented with deterministic numeric action IDs. By pruning non-interactive nodes, stripping stylistic noise, and mapping clickable interactive elements directly to numeric references (e.g., [42] Button: 'Submit Order'), the skill eliminates positional hallucinations and slashes token consumption by up to 85% compared to raw HTML injection. Furthermore, this skill enforces a strict Observe-Orient-Decide-Act (OODA) loop: after every click, scroll, or fill operation, the agent must wait for network idle or DOM stabilization, fetch a refreshed a11y tree delta, and verify state progression before issuing subsequent actions. This eliminates out-of-order execution, race conditions on dynamic client-side rendered applications, and unhandled synthetic click failures.
Prerequisites & Environment Requirements
Verified Search Intents & Long-Tail Queries Solved
This operational tutorial is engineered to provide deterministic solutions for these developer search queries:
Step-by-Step Execution Playbook
Local Skill Manifest Mounting & Directory Discovery
Mount the SKILL.md specification into your agent runtime's global or workspace-level skills registry.
Autonomous coding runtimes like Claude Code, Codex, and Cursor scan specific subdirectories for skill manifests. Placing the manifest into the workspace skill directory enables hot-reloading without restarting your editor session. The runtime parses the frontmatter triggers to automatically inject browser action procedures when web automation tasks are initiated.
mkdir -p .agents/skills/browser-agent-dom-action-tree && curl -fsSL https://askills.dev/api/skills/browser-agent-dom-action-tree/raw -o .agents/skills/browser-agent-dom-action-tree/SKILL.md---
name: "browser-agent-dom-action-tree"
description: "Control web browsers autonomously using accessibility DOM trees and click coordinates."
metadata:
author: "Browserbase"
version: "1.0.0"
runtime_compatibility:
- "codex"
- "claude-code"
- "cursor"
- "windsurf"
triggers:
- "control web browser with ai"
- "extract accessibility tree for agent"
- "click button in browser agent"
permissions:
fs_read: true
fs_write: "workspace"
shell_exec: false
net_access: false
---Ensure the skill directory resides inside your project root or user config (~/.claude/skills/ or .agents/skills/) to keep the SOP globally accessible across agent sessions.
Do not grant shell_exec: true or arbitrary network execution inside the skill manifest metadata; browser operations must execute through deterministic local scripts or standard Playwright test commands.
Install DOM Pruner & Playwright A11y Extraction Engine
Configure Playwright with accessibility snapshot tooling to convert runtime trees into numeric action nodes.
To enable the agent to query the accessibility tree, install Playwright and configure an extraction utility that leverages the Chrome DevTools Protocol (CDP) Accessibility domain or Playwright's native `page.accessibility.snapshot()`. This script dumps an indexed, simplified map directly into workspace storage for the agent to inspect.
npm install -D playwright && npx playwright install chromiumimport { chromium } from 'playwright';
import * as fs from 'fs';
export async function captureActionTree(url: string, outputPath: string = 'dist/a11y-tree.json') {
const browser = await chromium.launch({ headless: true });
const page = await browser.newPage();
await page.goto(url, { waitUntil: 'domcontentloaded' });
const snapshot = await page.accessibility.snapshot({ interestingOnly: true });
let elementCounter = 1;
function assignNumericIds(node: any): any {
if (!node) return null;
const isInteractive = ['button', 'link', 'textbox', 'checkbox', 'combobox'].includes(node.role);
const enrichedNode = {
id: isInteractive ? elementCounter++ : null,
role: node.role,
name: node.name || '',
value: node.value || undefined,
children: node.children ? node.children.map(assignNumericIds).filter(Boolean) : []
};
return enrichedNode;
}
const indexedTree = assignNumericIds(snapshot);
fs.writeFileSync(outputPath, JSON.stringify(indexedTree, null, 2));
await browser.close();
}Setting `interestingOnly: true` in Playwright's accessibility snapshot strips out redundant generic containers, reducing payload size by over 70% before context ingestion.
Dynamic Single Page Applications (SPAs) may not render target nodes on `domcontentloaded`. Always pair the snapshot with network idle checks or target role wait assertions.
Trigger Skill Execution via Agent Action Loops
Invoke the agent using standardized triggers to enforce numeric ID interaction and verified state transitions.
Provide natural language prompts containing matched frontmatter triggers. The agent will read `dist/a11y-tree.json`, map the target UI components to their integer IDs, and output deterministic Playwright commands rather than unpredictable CSS selectors.
claude "control web browser with ai: extract accessibility tree for agent on http://localhost:3000/checkout and fill out the shipping form"import { Page } from 'playwright';
// Agent executes actions based on numeric action mappings
export async function executeAgentAction(page: Page, action: { type: 'click' | 'fill', id: number, text?: string }, idMap: Record<number, string>) {
const selector = idMap[action.id];
if (!selector) throw new Error(`Action ID ${action.id} not found in DOM map.`);
if (action.type === 'click') {
await page.click(selector);
} else if (action.type === 'fill' && action.text !== undefined) {
await page.fill(selector, action.text);
}
await page.waitForLoadState('networkidle');
}Structure user prompts with explicit terminal goals (e.g., 'reach confirmation screen and output confirmation ID') so the agent terminates its loop cleanly.
Avoid passing whole page screenshots alongside raw DOM trees in the same prompt; use the a11y tree as the primary decision engine and rely on screenshots only for visual regression fallback.
Self-Healing State Verification & Lint Check
Run deterministic assertions on DOM transitions before accepting the agent's task completion.
The skill mandates running local verification before concluding. Execute automated test checks or diff verifications to ensure the agent did not generate broken interaction scripts or uncommitted artifacts outside the designated workspace path.
npx playwright test tests/browser-agent-verification.spec.ts && git status --porcelainimport { test, expect } from '@playwright/test';
test('verify deterministic browser agent action flow', async ({ page }) => {
await page.goto('http://localhost:3000/checkout');
await page.getByRole('textbox', { name: 'Full Name' }).fill('Ada Lovelace');
await page.getByRole('button', { name: 'Complete Order' }).click();
await expect(page.getByRole('heading', { name: 'Order Confirmed' })).toBeVisible();
});Instruct the agent to inspect the git diff of generated test scripts to ensure no secret values, session cookies, or authorization headers were hardcoded.
If the agent attempts to modify files outside the workspace root, fail the gate immediately and check the sandbox boundary permissions.
Real-World Scenario: Autonomous Form Automation on Multi-Step Checkout
“Use browser-agent-dom-action-tree to control web browser with ai on http://localhost:3000/onboarding. Extract accessibility tree for agent, fill out the user profile, accept terms checkbox, and click button in browser agent to advance to dashboard.”
Runtime Troubleshooting & Failure Modes
Root Cause: The agent attempted to click an element using generic CSS selectors instead of leveraging the deterministic accessibility tree node ID or role-and-name locator tuple.
await page.getByRole('button', { name: 'Submit Application' }).click(); // Enforce unique accessible name matching instead of element typeRoot Cause: The accessibility snapshot captured an element marked hidden or obscured by an active modal backdrop, or the agent attempted action before layout hydration finished.
await page.locator('[data-agent-id="14"]').waitFor({ state: 'visible', timeout: 5000 });
await page.locator('[data-agent-id="14"]').click({ force: false });Frequently Asked Questions (Web Browser Agent Accessibility Tree & Actions SOP)
Q:Can I use Web Browser Agent Accessibility Tree & Actions across Codex, Claude Code, and Cursor simultaneously?
Yes. The skill conforms to the universal SKILL.md specification supported across all modern agent runtimes. By placing the file in your repository under `.agents/skills/browser-agent-dom-action-tree/SKILL.md`, Codex, Claude Code, Windsurf, and Cursor will parse identical procedural triggers and sandboxing rules.
Q:How does Web Browser Agent Accessibility Tree & Actions prevent context window overflow during long agent sessions?
Standard DOM trees contain thousands of non-semantic nodes, attributes, and styling tags that consume up to 40,000 tokens per page view. This skill strips out non-interactive markup and generates a pruned accessibility tree with mapped integer IDs, lowering per-step token usage to under 1,500 tokens while retaining all interactive affordances.
Q:Does this skill require escalated root or container permissions?
No. The skill is audited with a security score of 98/100. It requires read permissions on the workspace and write permissions restricted strictly to local project artifacts (`workspace`). It explicitly sets `shell_exec: false` and `net_access: false` in its skill manifest, delegating execution to your sandboxed Playwright runtime.
Ready to equip your autonomous agent with Web Browser Agent Accessibility Tree & Actions?
Copy the complete audited SKILL.md specification or download the 1-click zip bundle directly from our verified registry.