mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
docs(API): add more explicit examples for page.evaluate (#1711)
This commit is contained in:
parent
9634d13be2
commit
3985dee54e
@ -680,11 +680,12 @@ List of all available devices is available in the source code: [DeviceDescriptor
|
||||
If the function, passed to the `page.evaluate`, returns a [Promise], then `page.evaluate` would wait for the promise to resolve and return its value.
|
||||
|
||||
If the function passed into `page.evaluate` returns a non-[Serializable] value, then `page.evaluate` resolves to `undefined`.
|
||||
Passing arguments to ```pageFunction```.
|
||||
|
||||
```js
|
||||
const result = await page.evaluate(() => {
|
||||
return Promise.resolve(8 * 7);
|
||||
});
|
||||
const result = await page.evaluate(x => {
|
||||
return Promise.resolve(8 * x);
|
||||
}, 7);
|
||||
console.log(result); // prints "56"
|
||||
```
|
||||
|
||||
@ -692,6 +693,8 @@ A string can also be passed in instead of a function.
|
||||
|
||||
```js
|
||||
console.log(await page.evaluate('1 + 2')); // prints "3"
|
||||
const x = 10;
|
||||
console.log(await page.evaluate(`1 + ${x}`)); // prints "11"
|
||||
```
|
||||
|
||||
[ElementHandle] instances can be passed as arguments to the `page.evaluate`:
|
||||
|
Loading…
Reference in New Issue
Block a user