diff --git a/docs/api.md b/docs/api.md index c1fcb0ef873b9..03129bc190522 100644 --- a/docs/api.md +++ b/docs/api.md @@ -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 `` 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); diff --git a/lib/ExecutionContext.js b/lib/ExecutionContext.js index 6bcda5dfa2e0d..7f10eb0bf5f10 100644 --- a/lib/ExecutionContext.js +++ b/lib/ExecutionContext.js @@ -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; } diff --git a/test/test.js b/test/test.js index 93235d69d3e8d..c54b639e2ac50 100644 --- a/test/test.js +++ b/test/test.js @@ -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');