Skip to content

Commit

Permalink
docs(API): add more explicit examples for page.evaluate (puppeteer#1711)
Browse files Browse the repository at this point in the history
  • Loading branch information
Octavian Cioaca authored and aslushnikov committed Jan 10, 2018
1 parent 9634d13 commit 3985dee
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -680,18 +680,21 @@ 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"
```

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`:
Expand Down

0 comments on commit 3985dee

Please sign in to comment.