Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:AIPexStudio AIPex formatSnapshot

From Leeroopedia
Knowledge Sources
Domains Accessibility, Text_Formatting
Last Updated 2026-10-24 12:00 GMT

Overview

Concrete function that formats a UnifiedSnapshot into indented text with interactive elements, focus annotations, and node attributes for LLM consumption.

Description

The formatSnapshot function takes a `UnifiedSnapshot` and produces a text representation of the accessibility tree. It builds a focus ancestor set to annotate the focused element path, filters nodes via `shouldIncludeInOutput` (interactive roles, images, meaningful text), formats each node with `getNodeAttributes` (uid, role, name, value, boolean properties), and indents children by depth. The focused node is marked with `*` and focus ancestors with `→`.

Usage

  • Format for LLM: `const text = formatSnapshot(snapshot)` to get page structure as text.
  • Used by snapshot tools to provide page context to the agent.

Code Reference

Source Location

  • Repository: AIPex
  • File: packages/browser-runtime/src/automation/snapshot-provider.ts
  • Lines: L456-462 (formatSnapshot), L315-363 (shouldIncludeInOutput), L368-429 (getNodeAttributes), L267-310 (buildFocusAncestorSet), L434-451 (formatNode)

Signature

export function formatSnapshot(snapshot: UnifiedSnapshot): string

// Internal helpers (not exported):
function shouldIncludeInOutput(node: TextSnapshotNode): boolean
function getNodeAttributes(node: TextSnapshotNode): string[]
function buildFocusAncestorSet(root: TextSnapshotNode, idToNode: Map<string, TextSnapshotNode>): Set<string>
function formatNode(node: TextSnapshotNode, depth: number, focusAncestorSet: Set<string>): string

Import

import { formatSnapshot } from "@aipexstudio/browser-runtime";

I/O Contract

Inputs

Name Type Required Description
snapshot UnifiedSnapshot Yes Snapshot with root and idToNode map

Outputs

Name Type Description
returns string Indented text representation of the accessibility tree

Usage Examples

Format Snapshot for LLM

import { createSnapshot, formatSnapshot } from "@aipexstudio/browser-runtime";

const snapshot = await createSnapshot(tabId);
if (snapshot) {
  const formatted = formatSnapshot(snapshot);
  // Example output:
  //  RootWebArea "My Page" <body>
  //   button "Submit" uid=abc123 <button> focusable
  //   * textbox "Email" uid=def456 <input> focusable focused
  //   → div "form-container"
}

Related Pages

Implements Principle

Uses Heuristics

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment