Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1161,7 +1161,7 @@ Dialog's type, could be one of the `alert`, `beforeunload`, `confirm` and `promp
[ConsoleMessage] objects are dispatched by page via the ['console'](#event-console) event.

#### consoleMessage.args
- <[Array]<[string]>>
- <[Array]<[JSHandle]>>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, this link is somehow broken here and in some other places.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vsemozhetbyt thanks, fixed in 3214bb7


#### consoleMessage.text
- <[string]>
Expand Down
2 changes: 1 addition & 1 deletion lib/Page.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
25 changes: 0 additions & 25 deletions lib/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,31 +83,6 @@ class Helper {
return remoteObject.value;
}

/**
* @param {!Session} client
* @param {!Object} remoteObject
* @return {!Promise<!Object>}
*/
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
Expand Down
10 changes: 6 additions & 4 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -696,9 +696,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 = [];
Expand Down Expand Up @@ -726,7 +728,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() {
Expand All @@ -736,7 +738,7 @@ describe('Page', function() {
page.evaluate(() => console.error(window)),
waitForEvents(page, 'console')
]);
expect(message.text).toBe('Window');
expect(message.text).toBe('JSHandle@object');
}));
});

Expand Down