wait_for_predicate
Wait until a JavaScript expression returns truthy in the browser, so automation proceeds only when a condition is met. Use it for app readiness, spinner removal, or list lengths instead of fixed sleeps.
Instructions
Wait until a JavaScript expression returns a truthy value.
The general-purpose wait, for when readiness is not "an element appeared": a list reached a length, a spinner class was removed, a global got populated, an animation finished.
wait_for_predicate("document.querySelectorAll('.row').length > 10")
wait_for_predicate("!document.querySelector('.spinner')")
wait_for_predicate("window.__APP_READY === true")Always prefer this to a fixed sleep — it returns the moment the condition
holds, instead of costing the full delay every time. If you only need to
wait after a click or a keypress, pass wait_for_predicate to that tool
instead and save the extra round-trip.
Args: js: JavaScript expression (or zero-argument function) re-evaluated in page context until it returns truthy. timeout_ms: Maximum time to wait (default 10 000). poll_ms: How often to re-evaluate, in milliseconds (default 100).
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| js | Yes | ||
| poll_ms | No | ||
| timeout_ms | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |