Skip to content

Models and errors

Public result models are frozen dataclasses unless this page states otherwise. Most preserve the complete native mapping in a raw field.

Evidence models

ModelFields and contract
SnapshotSpecselector, interactive, compact, max_depth, and urls define one accessibility capture.
Snapshottext, origin, url, spec, refs, and raw, plus ref lookup, refresh, and diff operations.
RefSnapshot-scoped id, selector, role, name, source snapshot, browser, and native metadata.
ActionResultaction, target, before, after, and diff for one completed ref mutation.
SnapshotDiffUnified text, addition, removal, and unchanged counts, changed, and raw source values.
WaitOne post-action text, URL, load, or ordered combined condition.

Snapshot.one() raises LookupError with the failed criteria and bounded candidate refs when criteria match zero or several refs. Snapshot.ref() raises KeyError for an unknown ID.

SnapshotSpec(selector=None, interactive=True, compact=False, max_depth=None, urls=False) accepts a non-negative maximum depth. A negative value raises ValueError.

Snapshot

MemberContract
textHuman-readable accessibility tree.
originPage URL or origin reported by the native engine.
urlAlias for origin.
specSnapshotSpec reused by refresh and ref mutations.
refsMapping of ref IDs to bound Ref objects.
rawNative snapshot response mapping.
ref(ref_id)Resolve an exact ID such as e1 or @e1.
one(*, role=None, name=None, contains=None, exact=False)Return exactly one ref or raise LookupError.
all(*, role=None, name=None, contains=None, exact=False)Return every matching ref as a tuple.
refresh()Capture the same SnapshotSpec again.
diff()Compare this snapshot with the active page and return SnapshotDiff.

Interactive representations keep snapshots, refs, action results, diffs, browser controllers, and close results bounded. Read .text, .raw, or the explicit fields when a code-mode task needs their complete content.

Ref

Every mutation returns ActionResult and accepts an optional wait condition.

MethodContract
click(*, button="left", click_count=1, new_tab=False, wait=None)Click with a mouse button and count.
fill(value, *, wait=None)Replace a form value.
type(text, *, wait=None)Type text with input events.
select(value, *, wait=None)Select an option value.
check(*, wait=None), uncheck(*, wait=None)Change checked state.
hover(*, wait=None), tap(*, wait=None), focus(*, wait=None)Move or focus interaction.
clear(*, wait=None), scroll_into_view(*, wait=None)Clear a control or reveal the target.
text()Return text content.
inner_text()Return rendered text.
input_value()Return the current form value.
attribute(name)Return an attribute value or None.
is_visible(), is_enabled(), is_checked()Return one boolean element state.
refresh(*, role=None, name=None, contains=None, exact=True)Resolve accessible metadata against a fresh snapshot.

Ref also exposes its source snapshot, browser, ID without @, native selector, accessible role, accessible name, and raw metadata. Native stale_ref and unknown_ref failures become StaleRefError.

Wait

ConstructorContract
Wait.text(text, *, timeout_ms=None)Wait for page text after the action.
Wait.url(url, *, timeout_ms=None)Wait for an active URL pattern.
Wait.loaded(state="load", *, timeout_ms=None)Wait for a load state.
Wait.all(*conditions)Apply one or more conditions in order.

Timeouts must be non-negative and use milliseconds. Wait.all() requires at least one condition.

ActionResult and ActionTransitionError

ActionResult(action, target, before, after, diff) records a completed ref mutation and its evidence.

ActionTransitionError means the mutation completed before the wait, snapshot, or diff stage failed. It exposes action, target, stage, before, optional after, and cause.

Page and artifact models

ModelFields and contract
ReadResultRequested url, final_url, status, content type, source, truncation state, content, and raw data.
ReadModeSelects Markdown negotiation, raw response body, outline, llms.txt, or llms-full.txt behavior.
ScreenshotFile path, format, annotations, raw capture data, bytes, copying, image loading, and notebook display.
ConsoleMessageConsole type, text, level, URL, line, column, and raw data.

Screenshot

MemberContract
bytes()Read the captured file bytes.
save(path)Copy the file and return a new Screenshot for the target path.
pil(*, mode=None)Load a Pillow image and optionally convert its mode.
imageLazily load and cache the Pillow image.
marimo(*, alt=None, width=None, height=None, rounded=False, caption=None, style=None)Return an image for a marimo reactive Python notebook.
annotationsRef number, role, accessible name, and bounding box for annotated elements.

pil() and image require the images extra. marimo() requires marimo in the application environment. PNG and JPEG captures expose notebook display data from their file bytes.

Session, tab, and storage models

ModelFields and contract
CloseResultclosed, restore status, save status, state path, save error, and raw terminal data.
SessionStatusNative identity, socket path, background PID, browser launch state, page count, engine, compatibility, restore checks, save state, and raw data.
SessionIdDerived session string, scope, source path, and hash.
TabInfoNative ID, URL, title, label, active state, optional stable target ID, and raw data.
TabSwitchResultSelected tab fields plus revived and dialog_blocked.
TabCloseResultClosed tab fields plus closed and active_tab_revived.
CookieName, value, domain, path, expiry, security flags, same-site value, and raw data.

Restore status values are load_failed, loaded, loaded_but_invalid, missing, not_configured, and pending.

Save status values are disabled, error, invalid_policy, no_browser, not_attempted, not_configured, saved, and skipped_restore_failed.

Network models

ModelFields and contract
NetworkRequestID, URL, method, resource type, status, and raw summary.
RequestDetailID, URL, method, status, request headers, response headers, optional body, and raw data.
RouteResponseOptional status, body, content type, and headers for one registered response.
ProxyConfigProxy server, bypass rules, username, and password.

HTTP Archive content modes are text, all, and none.

Accessibility models

An accessibility audit runs axe-core rules. It is separate from the accessibility snapshot used for refs.

ModelFields and contract
AccessibilityAuditAudited URL, axe-core version, counts, violations, incomplete checks, and raw data.
AccessibilityCountsViolation, incomplete, pass, and inapplicable rule counts.
AccessibilityIssueid, impact, help, help_url, tags, node_count, nodes, and raw.
AccessibilityNodeNested selector target, HTML excerpt, failure summary, and raw data.

WebMCP models

ModelFields and contract
WebMCPToolName, description, input schema, annotations, origin, frame identity, optional backend node ID, and raw data.
WebMCPInvocationinvocation_id, tool_name, frame_id, origin, status, duration_ms, raw_status, output, output_truncated, original_output_bytes, error, and raw.

Invocation status is pending, completed, canceled, failed, or timed_out.

Native response model

BrowserResponse is the complete envelope returned by browser.native.execute():

FieldContract
idNative JSON command ID.
actionNative action name.
successWhether the action succeeded.
dataRaw response data.
warningOptional native warning.
rawComplete response mapping.

Pending confirmation

PendingAction[T] exposes confirmation_id, native action, and confirmation-response details for one paused operation.

MethodContract
confirm() -> TRecheck current policy and domain containment, replay the action, and finish typed higher-level work. Another confirmation can raise ConfirmationRequired again.
deny() -> NoneReject and consume the pending action.
map(callback) -> PendingAction[U]Return a continuation that applies callback after the previous typed completion. Callbacks compose in registration order.

AsyncPendingAction exposes the same fields. Its confirm() and deny() methods are awaitable, while map() is synchronous.

A pending confirmation is tied to its ID and native session. A mismatched, consumed, or missing ID raises BrowserError. Policy replay also raises BrowserError when the file changed to deny the action, became invalid, or disappeared.

Errors

Catch SDK-owned failures through AgentBrowserError.

ErrorContract
AgentBrowserErrorCatchable base for SDK-owned browser, evidence, installation, persistence, and direct CDP failures.
BrowserErrorNative failure or Python safety rejection. Exposes action, response, and structured code.
ConfirmationRequiredPaused typed or checked action with a typed pending continuation.
StaleRefErrorExpired synchronous ref with refresh().
AsyncStaleRefErrorExpired asynchronous ref with awaitable refresh().
ActionTransitionErrorMutation completed, then its wait, snapshot, or diff stage failed.
NativeParseErrorA native payload missed a field or shape required by a typed model.
BrowserInstallErrorBrowser discovery or installation failed.
RestoreSaveErrorCleanup completed and persistence failed. Exposes terminal result.

Direct protocol errors live in agentbrowser.cdp:

ErrorContract
CDPErrorBase error for Python-owned direct protocol workflows.
CDPClosedErrorClient or controller is closed.
CDPProtocolErrorA protocol method returned an error.
CDPTimeoutErrorA method did not receive a response in time.
CDPTargetNotFoundError, CDPFrameNotFoundError, CDPContextNotFoundErrorNo object matched strict criteria.
CDPTargetAmbiguityError, CDPFrameAmbiguityError, CDPContextAmbiguityErrorSeveral objects matched strict criteria.
CDPStaleObjectErrorA cached frame or execution context expired after a page transition.
CDPEvaluationErrorJavaScript threw in the selected context.

Standard Python exceptions also define public contracts. Invalid options raise TypeError or ValueError. Operations after close raise RuntimeError. Missing optional image, marimo, or WebSocket dependencies raise ImportError. Async close can raise TimeoutError.

BrowserError, NativeParseError, ActionTransitionError, BrowserInstallError, RestoreSaveError, and CDPError inherit from AgentBrowserError. ConfirmationRequired inherits from BrowserError. Stale ref errors also inherit from BrowserError.

Embedded skill models

agentbrowser.skills returns Skill, SkillPart, and SkillFile dataclasses. A skill records its name, frontmatter description, main content, part metadata, loaded files, and hidden status. A skill file records its relative path and text content.

Released under the Apache License 2.0.