mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
chore(docs): document Frame class (#6188)
* chore: document Frame class
This commit is contained in:
@@ -7,21 +7,52 @@
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
waitForFunction(pageFunction: Function | string, options?: {
|
||||
polling?: string | number;
|
||||
timeout?: number;
|
||||
}, ...args: SerializableOrJSHandle[]): Promise<JSHandle>;
|
||||
waitForFunction(pageFunction: Function | string, options?: FrameWaitForFunctionOptions, ...args: SerializableOrJSHandle[]): Promise<JSHandle>;
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
| Parameter | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| pageFunction | Function \| string | |
|
||||
| options | { polling?: string \| number; timeout?: number; } | |
|
||||
| args | [SerializableOrJSHandle](./puppeteer.serializableorjshandle.md)<!-- -->\[\] | |
|
||||
| pageFunction | Function \| string | the function to evaluate in the frame context. |
|
||||
| options | [FrameWaitForFunctionOptions](./puppeteer.framewaitforfunctionoptions.md) | options to configure the polling method and timeout. |
|
||||
| args | [SerializableOrJSHandle](./puppeteer.serializableorjshandle.md)<!-- -->\[\] | arguments to pass to the <code>pageFunction</code>. |
|
||||
|
||||
<b>Returns:</b>
|
||||
|
||||
Promise<[JSHandle](./puppeteer.jshandle.md)<!-- -->>
|
||||
|
||||
the promise which resolve when the `pageFunction` returns a truthy value.
|
||||
|
||||
## Remarks
|
||||
|
||||
|
||||
## Example
|
||||
|
||||
The `waitForFunction` can be used to observe viewport size change:
|
||||
|
||||
```js
|
||||
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:
|
||||
|
||||
```js
|
||||
const selector = '.foo';
|
||||
await frame.waitForFunction(
|
||||
selector => !!document.querySelector(selector),
|
||||
{}, // empty options object
|
||||
selector
|
||||
);
|
||||
|
||||
```
|
||||
|
||||
|
||||
Reference in New Issue
Block a user