Skip to content

Browser session (multi-step)

$0.005 per callUSDC via x402POST /api/browser-session

A multi-step headless Chromium session: open it with a goto, then send one step per call...

Category: Web & documentsTags: browser automation session click type form scraping screenshotAlso found as: browser-steps browser-automation headless-session web-session click-and-type

Try in playground →

Details

A multi-step headless Chromium session: open it with a goto, then send one step per call (goto, click by CSS selector or text, type (optional Enter), wait for a selector, extract text, links or a table, screenshot). Each call is one paid step and answers its result and the page's url, title, status and text preview. The first call (no sessionId) returns session.id. Identity-bound: a session belongs to the wallet whose signed EVM x402 authorization opened it; another payer's step reads as unknown. Limits: 10 minutes per session, 2 minutes idle, 60 steps, 2 open sessions per wallet (another closes its least recently used idle one), one step at a time. "close": true ends the session after its step. Every navigation, redirect, frame and subresource passes render's public-address checks (http(s) only); downloads and pop-ups are refused. It never types into fields marked or recognized as a password, a one-time code or a payment card (by type, autocomplete, name, id, label, aria-label or placeholder), and never echoes or logs typed text. Each main-frame navigation checks the site's robots.txt first. It does not solve CAPTCHAs or evade bot detection: a site that blocks automated browsers stays blocked. A missing element answers 422 and keeps the session open; a full server answers 503 with Retry-After; neither is charged. Page content is untrusted (untrustedContent: true). Deterministic code, no model. Body: {"action":"goto","url":"https://…"}, then {"sessionId":"bs_…","action":"click","selector":"a"}.

Parameters

NameTypeRequiredDescription
sessionIdstringnosession.id from the call that opened the session; omit to open a new one (the first step must be goto)
actionstring (one of: goto, click, type, wait, extract, screenshot)yesThe step: goto, click, type, wait, extract or screenshot One of goto, click, type, wait, extract, screenshot.
urlstringnogoto: a public http(s) URL Up to 2048 characters. The example sends https://agent402.tools/.
selectorstringnoclick, type, wait: a CSS selector (first match). extract: optional scope (or the table to read)
textstringnoclick: visible text to click (instead of selector). type: the text to put in the field (up to 2000 characters, never echoed)
submitbooleannotype: press Enter after typing (default false)
timeoutMsintegernowait: how long to wait for the selector, 100 to 15000 (default 5000)
whatstring (one of: text, links, table)noextract: what to read (default text) One of text, links, table.
fullPagebooleannoscreenshot: the whole page up to 5000 px tall (default: the viewport)
closebooleannoEnd the session after this step (default false) The example sends true.

Example request

curl -i -X POST https://agent402.tools/api/browser-session \
  -H "Content-Type: application/json" \
  -d '{"action":"goto","url":"https://agent402.tools/","close":true}'

Watch a call get paid

RequestPOST /api/browser-session
402$0.005 USDC
SignPAYMENT-SIGNATURE
Settleon 11 chains
Answer200 OK
ReceiptAgent402-ReceiptEd25519

Example response

{
  "session": {
    "id": "bs_5mYb0p1Qm6X1R9tq3kq8m3vX0a8b3Kq2",
    "opened": true,
    "stepsUsed": 1,
    "stepsLeft": 59,
    "expiresAt": "2026-11-29T12:10:00.000Z",
    "idleTimeoutSeconds": 120,
    "closed": true,
    "closedReason": "closed"
  },
  "step": {
    "action": "goto",
    "ok": true,
    "status": 200
  },
  "page": {
    "url": "https://agent402.tools/",
    "title": "Page title",
    "status": 200,
    "textPreview": "…",
    "textChars": 4000
  },
  "untrustedContent": true
}
FieldTypeAlways presentIn the example
sessionobjectyes8 fields: id, opened, stepsUsed, stepsLeft, expiresAt and 3 more
stepobjectyes3 fields: action, ok, status
pageobjectyes5 fields: url, title, status, textPreview, textChars
untrustedContentbooleanyestrue

From an MCP client

catalog.call {
  "slug": "browser-session",
  "params": {
    "action": "goto",
    "url": "https://agent402.tools/",
    "close": true
  }
}

Hosted connector (https://agent402.tools/mcp): paid in the call. Stdio package (npx -y agent402-mcp@0.18.0): pays from a wallet.

Errors and behavior

Paid call (JavaScript agent)

import { wrapFetchWithPayment } from "@x402/fetch";
import { x402Client } from "@x402/core/client";
import { registerExactEvmScheme } from "@x402/evm/exact/client";
import { privateKeyToAccount } from "viem/accounts";

const client = new x402Client();
client.setSpendControls?.({ maxAmountPerPayment: "$0.005" }); // refuse any quote above this tool's price
registerExactEvmScheme(client, { signer: privateKeyToAccount(process.env.AGENT_KEY) });
const payFetch = wrapFetchWithPayment(fetch, client);

const res = await payFetch("https://agent402.tools/api/browser-session", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({
    "action": "goto",
    "url": "https://agent402.tools/",
    "close": true
  }),
});

Get a wallet or run npx -y agent402-mcp@0.18.0 wallet new.

The quote (Python)

import base64, json, urllib.error, urllib.request

req = urllib.request.Request("https://agent402.tools/api/browser-session", method="POST", data="{\"action\":\"goto\",\"url\":\"https://agent402.tools/\",\"close\":true}".encode(), headers={"Content-Type": "application/json"})
try:
    urllib.request.urlopen(req)
except urllib.error.HTTPError as e:
    quote = json.loads(base64.b64decode(e.headers["PAYMENT-REQUIRED"]))
    print(e.code, [(a["network"], a["amount"]) for a in quote["accepts"]])  # the price, per chain, in base units

Related tools