diff --git a/docs/api.md b/docs/api.md index 31a6c6fa13f..264175be453 100644 --- a/docs/api.md +++ b/docs/api.md @@ -1183,7 +1183,7 @@ Dialog's type, can be one of `alert`, `beforeunload`, `confirm` or `prompt`. [ConsoleMessage] objects are dispatched by page via the ['console'](#event-console) event. #### consoleMessage.args -- <[Array]<[string]>> +- <[Array]<[JSHandle]>> #### consoleMessage.text - <[string]> diff --git a/lib/Page.js b/lib/Page.js index f2b3ffdb2e2..f369dc3dd69 100644 --- a/lib/Page.js +++ b/lib/Page.js @@ -331,7 +331,7 @@ class Page extends EventEmitter { event.args.map(arg => helper.releaseObject(this._client, arg)); return; } - const values = await Promise.all(event.args.map(arg => helper.serializeRemoteObject(this._client, arg))); + const values = event.args.map(arg => this._frameManager.createJSHandle(event.executionContextId, arg)); const text = values.join(' '); const message = new ConsoleMessage(event.type, text, values); this.emit(Page.Events.Console, message); diff --git a/lib/helper.js b/lib/helper.js index 4056f055ee9..4245fad4f76 100644 --- a/lib/helper.js +++ b/lib/helper.js @@ -83,31 +83,6 @@ class Helper { return remoteObject.value; } - /** - * @param {!Session} client - * @param {!Object} remoteObject - * @return {!Promise} - */ - static async serializeRemoteObject(client, remoteObject) { - if (!remoteObject.objectId) - return Helper.valueFromRemoteObject(remoteObject); - if (remoteObject.subtype === 'promise') - return remoteObject.description; - try { - const response = await client.send('Runtime.callFunctionOn', { - objectId: remoteObject.objectId, - functionDeclaration: 'function() { return this; }', - returnByValue: true, - }); - return response.result.value; - } catch (e) { - // Return description for unserializable object, e.g. 'window'. - return remoteObject.description; - } finally { - Helper.releaseObject(client, remoteObject); - } - } - /** * @param {!Session} client * @param {!Object} remoteObject diff --git a/test/test.js b/test/test.js index 7d1079d5156..a1058f3feef 100644 --- a/test/test.js +++ b/test/test.js @@ -695,9 +695,11 @@ describe('Page', function() { page.evaluate(() => console.log('hello', 5, {foo: 'bar'})), waitForEvents(page, 'console') ]); - expect(message.text).toEqual('hello 5 [object Object]'); + expect(message.text).toEqual('hello 5 JSHandle@object'); expect(message.type).toEqual('log'); - expect(message.args).toEqual(['hello', 5, {foo: 'bar'}]); + expect(await message.args[0].jsonValue()).toEqual('hello'); + expect(await message.args[1].jsonValue()).toEqual(5); + expect(await message.args[2].jsonValue()).toEqual({foo: 'bar'}); })); it('should work for different console API calls', SX(async function() { const messages = []; @@ -725,7 +727,7 @@ describe('Page', function() { 'calling console.dir', 'calling console.warn', 'calling console.error', - 'Promise', + 'JSHandle@promise', ]); })); it('should not fail for window object', SX(async function() { @@ -735,7 +737,7 @@ describe('Page', function() { page.evaluate(() => console.error(window)), waitForEvents(page, 'console') ]); - expect(message.text).toBe('Window'); + expect(message.text).toBe('JSHandle@object'); })); });