/** * Accessibility Tree Extractor * * Extracts AI-friendly accessibility trees from Playwright pages using native * Playwright accessibility API. Provides stable element references and semantic * information for reliable element interaction. * * Inspired by agent-browser but using Playwright's built-in capabilities. */ import type { Page, Locator } from 'playwright'; import type { AccessibilityNode, AccessibilityTree, AccessibilityExtractionOptions } from '../types/accessibility.js'; import type { SemanticSelector } from '../types/index.js'; export declare class AccessibilityExtractor { private refCounter; /** * Extract accessibility tree from a Playwright page */ extract(page: Page, options?: AccessibilityExtractionOptions): Promise; /** * Convert Playwright accessibility node to our format */ private convertNode; /** * Enhance nodes with bounding box information */ private enhanceWithBounds; /** * Flatten tree into array for easier processing */ private flattenNodes; /** * Count interactive elements in tree */ private countInteractiveNodes; /** * Find element in accessibility tree by reference */ findByRef(nodes: AccessibilityNode[], ref: string): AccessibilityNode | null; /** * Get all elements matching a role */ findByRole(nodes: AccessibilityNode[], role: string): AccessibilityNode[]; /** * Get all interactive elements (buttons, links, inputs, etc.) */ getInteractiveElements(nodes: AccessibilityNode[]): AccessibilityNode[]; /** * Convert accessibility tree to compact text representation for LLM prompts */ toCompactString(nodes: AccessibilityNode[], indent?: number): string; /** * Extract just the interactive elements in a flat, AI-friendly format */ toInteractiveList(tree: AccessibilityTree): string; /** * Convert an AccessibilityNode to a SemanticSelector * This creates a more stable selector based on ARIA role and accessible name */ nodeToSemanticSelector(node: AccessibilityNode): SemanticSelector | null; /** * Create a Playwright locator from a SemanticSelector * This allows finding elements using semantic information instead of CSS selectors */ semanticSelectorToLocator(page: Page, semantic: SemanticSelector): Locator; /** * Find an element using semantic selector with fallback to CSS * Returns the locator that successfully found the element */ findElementWithFallback(page: Page, semanticSelector?: SemanticSelector, cssSelector?: string): Promise<{ locator: Locator; method: 'semantic' | 'css' | 'none'; }>; /** * Extract semantic selector from a CSS selector by inspecting the element * This is useful for learning semantic selectors from existing CSS selectors */ extractSemanticFromElement(page: Page, cssSelector: string): Promise; /** * Infer ARIA role from HTML tag name */ private inferRoleFromTag; } //# sourceMappingURL=accessibility-extractor.d.ts.map