Skip to content

Commit

Permalink
fix: return undefined when Page.evaluate encounters circular JSON (#983)
Browse files Browse the repository at this point in the history
  • Loading branch information
JoelEinbinder committed Oct 9, 2017
1 parent 3ecd98d commit a7672ac
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
4 changes: 4 additions & 0 deletions docs/api.md
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion lib/ExecutionContext.js
Expand Up @@ -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;
}
Expand Down
5 changes: 2 additions & 3 deletions test/test.js
Expand Up @@ -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');
Expand Down

0 comments on commit a7672ac

Please sign in to comment.