Skip to main content
Module

x/puppeteer/mod.ts>Frame#waitForFunction

A port of puppeteer running on Deno
Latest
method Frame.prototype.waitForFunction
Re-export
import { Frame } from "https://deno.land/x/puppeteer@16.2.0/mod.ts";

Examples

The waitForFunction can be used to observe viewport size change:

const puppeteer = require('puppeteer');

(async () => {
.  const browser = await puppeteer.launch();
.  const page = await browser.newPage();
.  const watchDog = page.mainFrame().waitForFunction('window.innerWidth < 100');
.  page.setViewport({width: 50, height: 50});
.  await watchDog;
.  await browser.close();
})();

To pass arguments from Node.js to the predicate of page.waitForFunction function:

const selector = '.foo';
await frame.waitForFunction(
  selector => !!document.querySelector(selector),
  {}, // empty options object
  selector
);

Type Parameters

Params extends unknown[]
optional
Func extends EvaluateFunc<Params> = EvaluateFunc<Params>

Parameters

pageFunction: Func | string
  • the function to evaluate in the frame context.
optional
options: FrameWaitForFunctionOptions
  • options to configure the polling method and timeout.
...args: Params
  • arguments to pass to the pageFunction.

Returns

Promise<HandleFor<Awaited<ReturnType<Func>>>>

the promise which resolve when the pageFunction returns a truthy value.