For AI agents: a documentation index is available at /llms.txt
Skip to main content

waitForFunction

Waits for a JavaScript predicate, evaluated in the page, to return a truthy value. The predicate may be a statement or a function expression and can be async.

**Usage Example:**

mutation WaitForFunction {
goto(url: "https://example.com") {
status
}

waitForFunction(fn: "window.dataLayer && window.dataLayer.length > 0") {
time
}
}

**Field Definition:**

waitForFunction(
fn: String!
polling: Float
timeout: Float
): WaitForFunction

Arguments

waitForFunction.fn ● String! non-null scalar

The JavaScript predicate to evaluate in the page. May be a statement (eg: "window.ready === true") or a function expression (eg: "() => document.readyState === 'complete'")

waitForFunction.polling ● Float scalar

The interval, in milliseconds, at which the predicate is re-evaluated. Defaults to 100ms

waitForFunction.timeout ● Float scalar

The maximum amount of time, in milliseconds, to wait for the predicate to become truthy, overriding any defaults. Default timeout is 30 seconds, or 30000.

Type

WaitForFunction object

Response returned after having waited for a JavaScript predicate to become truthy