mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
34ff00e2fe
* fix: added parts of website * fix: removed unnecessary lines * fix: updated contributing.md * fix: added parts of sidebar * fix: added all APIs * fix: added version 10.0.0 Co-authored-by: Jack Franklin <jacktfranklin@chromium.org>
1.7 KiB
1.7 KiB
Home > puppeteer > Frame > waitForFunction
Frame.waitForFunction() method
Signature:
waitForFunction(pageFunction: Function | string, options?: FrameWaitForFunctionOptions, ...args: SerializableOrJSHandle[]): Promise<JSHandle>;
Parameters
Parameter | Type | Description |
---|---|---|
pageFunction | Function | string | the function to evaluate in the frame context. |
options | FrameWaitForFunctionOptions | options to configure the polling method and timeout. |
args | SerializableOrJSHandle[] | arguments to pass to the pageFunction . |
Returns:
Promise<JSHandle>
the promise which resolve when the pageFunction
returns a truthy value.
Remarks
Example
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
);