Skip to main content
Glama

Wait for a condition

wait_for

Blocks until a specified page condition is met—CSS selector, text, JavaScript predicate, URL, field value, or network idle—then returns, enabling safe reads or actions on asynchronously loaded content.

Instructions

Block until a condition holds, then return. Provide exactly one of: selector (CSS present), text (appears in page text), predicate (JS expression truthy, MAIN world), networkIdle (no fetch/XHR in flight ~500ms — errors with 'network capture not active' on an http(s) page that loaded before the extension; a non-http document such as about:blank counts as idle). Follows document changes in the target tab within one timeout; network-idle timing restarts for each document. A predicate is judged SYNCHRONOUSLY: a returned promise is an object, so it counts as truthy — compare a resolved value instead. Predicates run through the debugger tier (works under a strict Content-Security-Policy; close DevTools on that tab); one that cannot parse or that the page refuses to evaluate fails immediately, while a missing global or element keeps polling and is reported with the timeout. Selector state supports attached/visible/hidden/detached; stableForMs requires truth across sampled polls and resets on false/errors/document changes. Timeouts include bounded poll/timing/document diagnostics without field values or predicate source. Use before reading/acting on content that loads asynchronously.

Tool call template

Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.

{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "tools/call",
  "params": {
    "arguments": {
      "tabId": "<tabId>"
    },
    "name": "wait_for"
  }
}

Input Schema

NameRequiredDescriptionDefault
urlNoWait for exact main-frame URL
textNoText to wait for in the page
stateNoSelector state; default attached. hidden also accepts absence
tabIdYesTarget tab ID (must be in the MCP group)
idleMsNoNetwork-idle threshold in ms (default 500)
frameIdNoFrame for selector/text/fieldValue only
selectorNoCSS selector to wait for
predicateNoJS expression evaluated in the page; wait until truthy
timeoutMsNoTimeout in ms (default 15000, max 270000; Chrome terminates a worker when one request exceeds 5 minutes)
fieldValueNoWait for a unique field value; checkbox/radio use boolean
networkIdleNoWait until the network has been idle (default 500ms; tune with idleMs)
stableForMsNoCondition must remain true across sampled observations for this duration; resets on document changes

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv0.24.1

TDQS

A4.5/5.0
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations supplied, the description carries the full burden and does so: it discloses the network-idle error string, that idle timing restarts per document, the debugger/CSP requirement for predicates, the DevTools conflict, which failure classes fail immediately versus poll until timeout, and what timeout diagnostics contain (no field values or predicate source). The synchronous-predicate gotcha (a returned promise is an object and therefore truthy) is exactly the kind of non-obvious behavior an agent could not infer from the schema.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Front-loaded with the core contract before any caveats, and virtually every clause carries information. It is nonetheless dense and parenthetical-heavy, packing several distinct caveats into single semicolon-chained sentences, which makes it slower to scan than it needs to be.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a 12-parameter tool with no annotations and no output schema, the description covers evaluation semantics, failure modes, timing resets, and diagnostics thoroughly. The notable remaining gap is what a successful call actually returns — the description says 'then return' but never says what comes back, which is the one thing the absent output schema cannot supply.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100%, so the baseline is 3, but the description adds real meaning: the mutually-exclusive 'exactly one of' constraint is not encoded as a oneOf in the schema, stableForMs is clarified to reset on false and error as well as document changes, and predicate's evaluation world and truthiness rule are spelled out. Enum values for state are repeated rather than added to, which keeps it off a 5.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

States a specific verb and resource — 'Block until a condition holds, then return' — and enumerates exactly the four condition modes (selector, text, predicate, networkIdle) it accepts. The closing line 'Use before reading/acting on content that loads asynchronously' situates it against the read/extract siblings without needing to name them.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Gives a concrete usage rule ('Provide exactly one of:' the four modes) and a clear triggering context ('Use before reading/acting on content that loads asynchronously'). It also warns off the networkIdle mode in a specific situation (http(s) page loaded before the extension). No explicit 'when not to use this, use X instead' routing to a named sibling, so it falls short of a 5.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.