mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
fix: return undefined when Page.evaluate encounters circular JSON (#983)
This commit is contained in:
parent
3ecd98d634
commit
a7672acb85
@ -500,6 +500,8 @@ 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`.
|
||||
|
||||
```js
|
||||
const result = await page.evaluate(() => {
|
||||
return Promise.resolve(8 * 7);
|
||||
@ -1270,6 +1272,8 @@ Adds a `<link rel="stylesheet">` tag to the frame with the desired url.
|
||||
|
||||
If the function, passed to the `frame.evaluate`, returns a [Promise], then `frame.evaluate` would wait for the promise to resolve and return its value.
|
||||
|
||||
If the function passed into `frame.evaluate` returns a non-[Serializable] value, then `frame.evaluate` resolves to `undefined`.
|
||||
|
||||
```js
|
||||
const result = await frame.evaluate(() => {
|
||||
return Promise.resolve(8 * 7);
|
||||
|
@ -35,7 +35,7 @@ class ExecutionContext {
|
||||
*/
|
||||
async evaluate(pageFunction, ...args) {
|
||||
const handle = await this.evaluateHandle(pageFunction, ...args);
|
||||
const result = await handle.jsonValue();
|
||||
const result = await handle.jsonValue().catch(error => undefined);
|
||||
await handle.dispose();
|
||||
return result;
|
||||
}
|
||||
|
@ -266,9 +266,8 @@ describe('Page', function() {
|
||||
expect(result).toBe(true);
|
||||
}));
|
||||
it('should fail for window object', SX(async function() {
|
||||
let error = null;
|
||||
await page.evaluate(() => window).catch(e => error = e);
|
||||
expect(error.message).toContain('Converting circular structure to JSON');
|
||||
const result = await page.evaluate(() => window);
|
||||
expect(result).toBe(undefined);
|
||||
}));
|
||||
it('should accept a string', SX(async function() {
|
||||
const result = await page.evaluate('1 + 2');
|
||||
|
Loading…
Reference in New Issue
Block a user