Docs/SDK/Snapshot API

Snapshot API

The snapshot() function captures the current page state and returns all interactive elements with semantic information.

Basic Usage

from sentience import snapshot, SnapshotOptions, SnapshotFilter

# Basic snapshot (uses default options)
snap = snapshot(browser)

# With screenshot and limit
snap = snapshot(browser, SnapshotOptions(
    screenshot=True,
    limit=200
))

# Force local processing (no credits used)
snap = snapshot(browser, SnapshotOptions(use_api=False))

# With filtering
snap = snapshot(browser, SnapshotOptions(
    filter=SnapshotFilter(
        min_area=100,
        allowed_roles=["button", "link"]
    )
))

# Or use dict for filter (also supported)
snap = snapshot(browser, SnapshotOptions(
    filter={"min_area": 100, "allowed_roles": ["button", "link"]}
))

Important Notes

Credit Consumption:

Payload Size Limit:

Parameters

Python:

SnapshotOptions fields:

TypeScript:

Returns

Snapshot object with:

Element Properties

Each element in snapshot.elements has:

Visual Overlay Feature

When show_overlay=True, Sentience displays a visual overlay in the browser highlighting all detected elements:

Color Coding:

Visual Indicators:

Use Cases:

# Example: Debug why a button isn't being clicked
from sentience import SnapshotOptions

browser.goto("https://example.com")
snap = snapshot(browser, SnapshotOptions(show_overlay=True))  # See what's detected
time.sleep(6)  # Wait to inspect the overlay

# Check if your target button is in the results
button = find(snap, "role=button text~'Submit'")
if not button:
    print("❌ Button not found - check the overlay to see what's detected")

ML Reranking (Goal-Based Optimization)

When you provide a goal parameter in SnapshotOptions, the server uses an ONNX-based machine learning model to rerank elements based on relevance to your goal. This dramatically improves element selection accuracy for agent tasks.

# Trigger ML reranking by providing a goal
snap = snapshot(browser, SnapshotOptions(
    goal="Click the login button",
    limit=50
))

# Elements are now sorted by ML relevance, not just heuristic importance
for element in snap.elements[:5]:
    print(f"[{element.id}] {element.role}: {element.text}")
    if element.ml_probability:
        print(f"  ML Confidence: {element.ml_probability:.2%}")
        print(f"  Moved from position {element.heuristic_index}{element.rerank_index}")

When ML fields are present:

What the fields mean: