Overview
Concrete functions for looking up accessibility tree nodes by UID and validating UID existence in the current snapshot cache.
Description
The getNodeByUid function retrieves a `TextSnapshotNode` from the cached snapshot by its UID string. It checks the DOM cache first (background mode) and falls back to the CDP cache in snapshotManager. The isValidUid function checks if a UID exists in the current snapshot. Both functions allow tool-call handlers to resolve element UIDs from AI agent params to actual node objects without re-creating the snapshot.
Usage
- Resolve UID to node: `const node = getNodeByUid(tabId, uid)`
- Validate before action: `if (!isValidUid(tabId, uid)) throw new Error("Invalid UID")`
- Must be called after `createSnapshot(tabId)` to have a cached snapshot.
Code Reference
Source Location
- Repository: AIPex
- File: packages/browser-runtime/src/automation/snapshot-provider.ts
- Lines: L240-262 (getNodeByUid), L568-574 (isValidUid), L217-235 (getSnapshot)
Signature
export function getNodeByUid(tabId: number, uid: string): TextSnapshotNode | null
export function isValidUid(tabId: number, uid: string): boolean
export function getSnapshot(tabId: number): UnifiedSnapshot | null
export function clearSnapshot(tabId: number): void
export function clearAllSnapshots(): void
Import
import { getNodeByUid, isValidUid, getSnapshot, clearSnapshot } from "@aipexstudio/browser-runtime";
I/O Contract
Inputs
| Name |
Type |
Required |
Description
|
| tabId |
number |
Yes |
Target browser tab ID
|
| uid |
string |
Yes |
Element UID from snapshot
|
Outputs
| Name |
Type |
Description
|
| returns |
null |
Node with role, name, children, or null if not found
|
| returns |
boolean |
True if UID exists in snapshot (isValidUid)
|
Usage Examples
Resolve UID for Element Action
import { getNodeByUid, isValidUid } from "@aipexstudio/browser-runtime";
const uid = "abc123"; // From AI tool call params
if (!isValidUid(tabId, uid)) {
throw new Error(`Element ${uid} not found in snapshot`);
}
const node = getNodeByUid(tabId, uid);
console.log(node.role, node.name); // "button", "Submit"
Related Pages
Implements Principle
Uses Heuristics
Requires Environment
Page Connections
Double-click a node to navigate. Hold to expand connections.