feat(console): dispatch JSHandles as console arguments (#975)

This patch starts dispatching JSHandle instances as console arguments.

BREAKING CHANGE: this changes the API of the ConsoleMessage.

Fixes #324.
This commit is contained in:
Andrey Lushnikov
2017-10-09 17:01:01 -07:00
committed by GitHub
parent 8d1d9fec65
commit e6af6e19d6
4 changed files with 8 additions and 31 deletions

View File

@@ -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);

View File

@@ -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