assert - kubed-io/selenium-flow GitHub Wiki

assert

Check the page with JavaScript that must return true; otherwise the call fails. Return a boolean, not the thing itself: return !!document.querySelector('#total').

MCP tool assert
HTTP POST /browser/assert

It asks again until the answer is true or wait_timeout passes (0 asks once), so it can follow a click without knowing how long the page takes. For a guard that must hold before acting, set stable_for: the answer has to stay true that many seconds, which catches a page that is true for a moment before it redirects.

message is the sentence a failure shows, and in a flow it becomes the failing step's error.

Parameters

Name Type Required Default
script string yes —
message string no —
url string no —
wait_timeout integer no 30
stable_for number no 0

Every call names its workspace: an X-Workspace header, or ?workspace=<name>. Sending both is refused. See Workspaces.

Returns

Field Type Notes
asserted boolean Always true: a false assertion is an error, not a result.
script string The expression that was true.
stable_for number Present when a hold was asked for: the seconds the answer had to stay true, and did.
url string Current URL after the action.
title string Page title after the action.
site_data object Present only when site data was restored, skipped or forgotten in this call.
page object Present only when this browser was opened with capture=true and the page reported a failure while the call ran: what it caused, and where to read it.

Errors

Status Means
400 The request cannot succeed as sent — a missing field, a value that was rejected, or a locator that matched nothing before the wait ran out. Do not retry it unchanged.
401 Missing or wrong bearer token.
404 No such browser session. It ended, the Grid reaped it, or the id was never real. Open a new one and retry.
413 The body is over its cap: 1 MiB of JSON, 64 MiB of upload, 1 MiB of flow YAML. Send less; retrying it unchanged will fail again.
500 Something failed that this server did not expect.
503 The Grid could not serve this — unreachable, or no free slot for a new browser. Worth retrying after a wait.

Over MCP the same failures arrive as a tool error.

Example

MCP

assert(script="…")

HTTP

curl -X POST $SELENIUM_FLOW/browser/assert \
  -H "Authorization: Bearer $TOKEN" \
  -H "X-Workspace: $WORKSPACE" \
  -H 'Content-Type: application/json' \
  -d '{
    "script": "…"
  }'

← All actions · Installing · Deployment

⚠️ **GitHub.com Fallback** ⚠️