Spotted something off?Report on Discord
guides

Wait For Function

Pause browser execution until a custom JavaScript expression evaluates to true, with configurable timeout.

Updated May 28, 2025

Waits until a custom JavaScript expression evaluates to true inside the browser, useful for dynamic content or specific page states.

Command

"wait_for_function"

One of the browser actions β€” use wait_for_selector to wait on the DOM, or wait_for_load_state to wait on the page load lifecycle instead of a JavaScript expression.

Parameters

Parameter Type Required Description
code string Yes JavaScript code to evaluate. Must return a truthy value to proceed.
timeout number No Max time (ms) to wait for the condition (default: 60000 ms).

Example

Wait for element to appear

javascript1 lines

Wait for text and status change

javascript4 lines

Example Request (cURL)

bash17 lines
Want to run this request directly in your browser?to try it live with your own API key.

Notes

  • The condition is evaluated in the browser context.
  • It polls every 200ms until the condition is met.
  • Throws an error if the timeout is reached.
  • Any JavaScript expression that evaluates to true/false can be used.