Realm.waitForFunction() method
Waits for a function to return a truthy value when evaluated in the realm's context.
Arguments can be passed from Node.js to pageFunction.
Signature
class Realm {
waitForFunction<
Params extends unknown[],
Func extends EvaluateFunc<Params> = EvaluateFunc<Params>,
>(
pageFunction: Func | string,
options?: {
polling?: 'raf' | 'mutation' | number;
timeout?: number;
root?: ElementHandle<Node>;
signal?: AbortSignal;
},
...args: Params
): Promise<HandleFor<Awaited<ReturnType<Func>>>>;
}
Parameters
Parameter | Type | Description |
|---|---|---|
pageFunction | Func | string | A function to evaluate in the realm. |
options | { polling?: 'raf' | 'mutation' | number; timeout?: number; root?: ElementHandle<Node>; signal?: AbortSignal; } | (Optional) Options for polling and timeouts. |
args | Params | Arguments to pass to the function. |
Returns:
Promise<HandleFor<Awaited<ReturnType<Func>>>>
A promise that resolves when the function returns a truthy value.
Example
const selector = '.foo';
await realm.waitForFunction(
selector => !!document.querySelector(selector),
{},
selector,
);