docs: clarify Page.waitForFunction() docs to mention that it will w… (#11592)

This commit is contained in:
Ben Elliott 2023-12-28 04:11:58 +00:00 committed by GitHub
parent 4468ab21ed
commit 0651d2c68e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 16 deletions

View File

@ -155,7 +155,7 @@ page.off('request', logRequest);
| [waitForDevicePrompt(options)](./puppeteer.page.waitfordeviceprompt.md) | | <p>This method is typically coupled with an action that triggers a device request from an api such as WebBluetooth.</p><p>:::caution</p><p>This must be called before the device request is made. It will not return a currently active device prompt.</p><p>:::</p> | | [waitForDevicePrompt(options)](./puppeteer.page.waitfordeviceprompt.md) | | <p>This method is typically coupled with an action that triggers a device request from an api such as WebBluetooth.</p><p>:::caution</p><p>This must be called before the device request is made. It will not return a currently active device prompt.</p><p>:::</p> |
| [waitForFileChooser(options)](./puppeteer.page.waitforfilechooser.md) | | <p>This method is typically coupled with an action that triggers file choosing.</p><p>:::caution</p><p>This must be called before the file chooser is launched. It will not return a currently active file chooser.</p><p>:::</p> | | [waitForFileChooser(options)](./puppeteer.page.waitforfilechooser.md) | | <p>This method is typically coupled with an action that triggers file choosing.</p><p>:::caution</p><p>This must be called before the file chooser is launched. It will not return a currently active file chooser.</p><p>:::</p> |
| [waitForFrame(urlOrPredicate, options)](./puppeteer.page.waitforframe.md) | | Waits for a frame matching the given conditions to appear. | | [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, <code>pageFunction</code>, 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. | | [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) | | | | [waitForNetworkIdle(options)](./puppeteer.page.waitfornetworkidle.md) | | |
| [waitForRequest(urlOrPredicate, options)](./puppeteer.page.waitforrequest.md) | | | | [waitForRequest(urlOrPredicate, options)](./puppeteer.page.waitforrequest.md) | | |

View File

@ -4,7 +4,7 @@ sidebar_label: Page.waitForFunction
# Page.waitForFunction() method # 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: #### Signature:
@ -23,11 +23,11 @@ class Page {
## Parameters ## Parameters
| Parameter | Type | Description | | Parameter | Type | Description |
| ------------ | ------------------------------------------------------------------------- | ------------------------------------------------------ | | ------------ | ------------------------------------------------------------------------- | ---------------------------------------------------------------------------- |
| pageFunction | Func \| string | Function to be evaluated in browser context | | 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. | | options | [FrameWaitForFunctionOptions](./puppeteer.framewaitforfunctionoptions.md) | _(Optional)_ Options for configuring waiting behavior. |
| args | Params | | | args | Params | |
**Returns:** **Returns:**
@ -35,7 +35,7 @@ Promise&lt;[HandleFor](./puppeteer.handlefor.md)&lt;Awaited&lt;ReturnType&lt;Fun
## Example 1 ## 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 ```ts
import puppeteer from 'puppeteer'; import puppeteer from 'puppeteer';
@ -51,7 +51,7 @@ import puppeteer from 'puppeteer';
## Example 2 ## 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 ```ts
const selector = '.foo'; const selector = '.foo';
@ -64,7 +64,7 @@ await page.waitForFunction(
## Example 3 ## Example 3
The predicate of [Page.waitForFunction()](./puppeteer.page.waitforfunction.md) can be asynchronous too: The provided `pageFunction` can be asynchronous:
```ts ```ts
const username = 'github-username'; const username = 'github-username';

View File

@ -2901,10 +2901,11 @@ export abstract class Page extends EventEmitter<PageEvents> {
} }
/** /**
* 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 * @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 * ```ts
* import puppeteer from 'puppeteer'; * import puppeteer from 'puppeteer';
@ -2919,8 +2920,7 @@ export abstract class Page extends EventEmitter<PageEvents> {
* ``` * ```
* *
* @example * @example
* To pass arguments from node.js to the predicate of * Arguments can be passed from Node.js to `pageFunction`:
* {@link Page.waitForFunction} function:
* *
* ```ts * ```ts
* const selector = '.foo'; * const selector = '.foo';
@ -2932,7 +2932,7 @@ export abstract class Page extends EventEmitter<PageEvents> {
* ``` * ```
* *
* @example * @example
* The predicate of {@link Page.waitForFunction} can be asynchronous too: * The provided `pageFunction` can be asynchronous:
* *
* ```ts * ```ts
* const username = 'github-username'; * const username = 'github-username';
@ -2954,7 +2954,8 @@ export abstract class Page extends EventEmitter<PageEvents> {
* ); * );
* ``` * ```
* *
* @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. * @param options - Options for configuring waiting behavior.
*/ */
waitForFunction< waitForFunction<