From 3985dee54eb2ec02c38d2017df49de0f868d86bf Mon Sep 17 00:00:00 2001 From: Octavian Cioaca Date: Wed, 10 Jan 2018 08:05:52 +0100 Subject: [PATCH] docs(API): add more explicit examples for page.evaluate (#1711) --- docs/api.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/docs/api.md b/docs/api.md index 5aae0cbd..b6a5b051 100644 --- a/docs/api.md +++ b/docs/api.md @@ -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`: