@ulpi/browse

Action Context

Enriched write command responses that show what changed — URL, title, tabs, dialogs, console errors — eliminating expensive snapshot calls between steps.

Overview

Action context appends a compact [context] line to write command responses showing what changed on the page. Instead of calling snapshot after every action, agents can read the context line to know if a navigation occurred, the title changed, a dialog appeared, or console errors were logged.

$ browse --context goto https://example.com/cart
Navigated to https://example.com/cart (200)
[context] -> /cart | title: "Shopping Cart" | errors: +1

When nothing changes (e.g., filling an input), no context line is added:

$ browse --context fill @e4 "test@example.com"
Filled @e4

Activation

There are three ways to enable action context:

1. CLI Flag

browse --context goto https://example.com
browse --context click @e3

2. Session Toggle

Enable per-session at runtime — stays on until you turn it off or the session closes:

browse set context on     # Enable for this session
browse goto https://...   # Now includes [context] without --context flag
browse set context off    # Disable

3. Environment Variable or Config

# Environment variable
export BROWSE_CONTEXT=1
browse goto https://example.com   # Context enabled
browse.json
{
  "context": true
}

MCP Mode

In MCP mode (browse --mcp), action context is always enabled for write commands. No opt-in needed — MCP clients always benefit from knowing what changed.

What's Reported

The context line includes only fields that changed:

FieldExampleWhen Reported
URL change-> /checkoutURL pathname changed (query params stripped for privacy)
Title changetitle: "Order Summary"document.title changed
Tab counttabs: 3A tab was opened or closed
Dialog appeareddialog: [confirm] "Delete item?"A dialog (alert, confirm, prompt) appeared
Dialog dismisseddialog dismissedA previously visible dialog was dismissed
Console errorserrors: +2New console.error calls since last capture

Multiple changes in one action are combined:

[context] -> /checkout | title: "Checkout" | errors: +1

How It Works

  1. Before the write command executes: capture page state (URL, title, tab count, dialog, error count)
  2. Execute the write command (click, goto, fill, etc.)
  3. After execution: capture state again and diff against the before-snapshot
  4. If anything changed, format and append the [context] line

State capture is O(1) — it reads running counters, not scanning buffers. Zero overhead when context is disabled.

Interaction with Other Modes

JSON Mode

Context is included in the data field before JSON wrapping:

$ browse --context --json goto https://example.com
{"success":true,"data":"Navigated to https://example.com (200)\n[context] -> / | title: \"Example\"","command":"goto"}

Max Output

The --max-output truncation is applied to the base result before the context line is appended. This means the context line is never truncated — you always see what changed even on large outputs.

Content Boundaries

Context is appended outside content boundaries (write commands don't produce page content).

Best Practices

  • Enable for multi-step workflows where you'd otherwise call snapshot or url between actions
  • Disable for simple single-command usage where you don't need the extra output
  • Use the session toggle (set context on) when entering a complex workflow, then set context off when done
  • In MCP mode, it's always on — no action needed

On this page