diff --git a/docs/api/puppeteer.page.md b/docs/api/puppeteer.page.md index 16d9037f39d..cb5484d51b1 100644 --- a/docs/api/puppeteer.page.md +++ b/docs/api/puppeteer.page.md @@ -155,7 +155,7 @@ page.off('request', logRequest); | [waitForDevicePrompt(options)](./puppeteer.page.waitfordeviceprompt.md) | |

This method is typically coupled with an action that triggers a device request from an api such as WebBluetooth.

:::caution

This must be called before the device request is made. It will not return a currently active device prompt.

:::

| | [waitForFileChooser(options)](./puppeteer.page.waitforfilechooser.md) | |

This method is typically coupled with an action that triggers file choosing.

:::caution

This must be called before the file chooser is launched. It will not return a currently active file chooser.

:::

| | [waitForFrame(urlOrPredicate, options)](./puppeteer.page.waitforframe.md) | | Waits for a frame matching the given conditions to appear. | -| [waitForFunction(pageFunction, options, args)](./puppeteer.page.waitforfunction.md) | | Waits for a function to finish evaluating in the page's context. | +| [waitForFunction(pageFunction, options, args)](./puppeteer.page.waitforfunction.md) | | Waits for the provided function, pageFunction, to return a truthy value when evaluated in the page's context. | | [waitForNavigation(options)](./puppeteer.page.waitfornavigation.md) | | Waits for the page to navigate to a new URL or to reload. It is useful when you run code that will indirectly cause the page to navigate. | | [waitForNetworkIdle(options)](./puppeteer.page.waitfornetworkidle.md) | | | | [waitForRequest(urlOrPredicate, options)](./puppeteer.page.waitforrequest.md) | | | diff --git a/docs/api/puppeteer.page.waitforfunction.md b/docs/api/puppeteer.page.waitforfunction.md index 4ad53a6f946..d5efb8d7fe6 100644 --- a/docs/api/puppeteer.page.waitforfunction.md +++ b/docs/api/puppeteer.page.waitforfunction.md @@ -4,7 +4,7 @@ sidebar_label: Page.waitForFunction # Page.waitForFunction() method -Waits for a function to finish evaluating in the page's context. +Waits for the provided function, `pageFunction`, to return a truthy value when evaluated in the page's context. #### Signature: @@ -23,11 +23,11 @@ class Page { ## Parameters -| Parameter | Type | Description | -| ------------ | ------------------------------------------------------------------------- | ------------------------------------------------------ | -| pageFunction | Func \| string | Function to be evaluated in browser context | -| options | [FrameWaitForFunctionOptions](./puppeteer.framewaitforfunctionoptions.md) | _(Optional)_ Options for configuring waiting behavior. | -| args | Params | | +| Parameter | Type | Description | +| ------------ | ------------------------------------------------------------------------- | ---------------------------------------------------------------------------- | +| pageFunction | Func \| string | Function to be evaluated in browser context until it returns a truthy value. | +| options | [FrameWaitForFunctionOptions](./puppeteer.framewaitforfunctionoptions.md) | _(Optional)_ Options for configuring waiting behavior. | +| args | Params | | **Returns:** @@ -35,7 +35,7 @@ Promise<[HandleFor](./puppeteer.handlefor.md)<Awaited<ReturnType<Fun ## Example 1 -The [Page.waitForFunction()](./puppeteer.page.waitforfunction.md) can be used to observe viewport size change: +[Page.waitForFunction()](./puppeteer.page.waitforfunction.md) can be used to observe a viewport size change: ```ts import puppeteer from 'puppeteer'; @@ -51,7 +51,7 @@ import puppeteer from 'puppeteer'; ## Example 2 -To pass arguments from node.js to the predicate of [Page.waitForFunction()](./puppeteer.page.waitforfunction.md) function: +Arguments can be passed from Node.js to `pageFunction`: ```ts const selector = '.foo'; @@ -64,7 +64,7 @@ await page.waitForFunction( ## Example 3 -The predicate of [Page.waitForFunction()](./puppeteer.page.waitforfunction.md) can be asynchronous too: +The provided `pageFunction` can be asynchronous: ```ts const username = 'github-username'; diff --git a/packages/puppeteer-core/src/api/Page.ts b/packages/puppeteer-core/src/api/Page.ts index d42d7f0a428..fb07df2637f 100644 --- a/packages/puppeteer-core/src/api/Page.ts +++ b/packages/puppeteer-core/src/api/Page.ts @@ -2901,10 +2901,11 @@ export abstract class Page extends EventEmitter { } /** - * Waits for a function to finish evaluating in the page's context. + * Waits for the provided function, `pageFunction`, to return a truthy value when + * evaluated in the page's context. * * @example - * The {@link Page.waitForFunction} can be used to observe viewport size change: + * {@link Page.waitForFunction} can be used to observe a viewport size change: * * ```ts * import puppeteer from 'puppeteer'; @@ -2919,8 +2920,7 @@ export abstract class Page extends EventEmitter { * ``` * * @example - * To pass arguments from node.js to the predicate of - * {@link Page.waitForFunction} function: + * Arguments can be passed from Node.js to `pageFunction`: * * ```ts * const selector = '.foo'; @@ -2932,7 +2932,7 @@ export abstract class Page extends EventEmitter { * ``` * * @example - * The predicate of {@link Page.waitForFunction} can be asynchronous too: + * The provided `pageFunction` can be asynchronous: * * ```ts * const username = 'github-username'; @@ -2954,7 +2954,8 @@ export abstract class Page extends EventEmitter { * ); * ``` * - * @param pageFunction - Function to be evaluated in browser context + * @param pageFunction - Function to be evaluated in browser context until it returns a + * truthy value. * @param options - Options for configuring waiting behavior. */ waitForFunction<