mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
docs(api.md): fix missing await in examples (#1801)
`frame.executionContext()` returns a Promise, so running examples without `await` results in exceptions
This commit is contained in:
parent
8c93084316
commit
25b35c5789
@ -1743,7 +1743,7 @@ The class represents a context for JavaScript execution. Examples of JavaScript
|
|||||||
If the function, passed to the `executionContext.evaluate`, returns a [Promise], then `executionContext.evaluate` would wait for the promise to resolve and return its value.
|
If the function, passed to the `executionContext.evaluate`, returns a [Promise], then `executionContext.evaluate` would wait for the promise to resolve and return its value.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const executionContext = page.mainFrame().executionContext();
|
const executionContext = await page.mainFrame().executionContext();
|
||||||
const result = await executionContext.evaluate(() => Promise.resolve(8 * 7));
|
const result = await executionContext.evaluate(() => Promise.resolve(8 * 7));
|
||||||
console.log(result); // prints "56"
|
console.log(result); // prints "56"
|
||||||
```
|
```
|
||||||
@ -1772,7 +1772,7 @@ console.log(result); // prints '3'.
|
|||||||
If the function, passed to the `executionContext.evaluateHandle`, returns a [Promise], then `executionContext.evaluteHandle` would wait for the promise to resolve and return its value.
|
If the function, passed to the `executionContext.evaluateHandle`, returns a [Promise], then `executionContext.evaluteHandle` would wait for the promise to resolve and return its value.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const context = page.mainFrame().executionContext();
|
const context = await page.mainFrame().executionContext();
|
||||||
const aHandle = await context.evaluateHandle(() => Promise.resolve(self));
|
const aHandle = await context.evaluateHandle(() => Promise.resolve(self));
|
||||||
aHandle; // Handle for the global object.
|
aHandle; // Handle for the global object.
|
||||||
```
|
```
|
||||||
|
Loading…
Reference in New Issue
Block a user