mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
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:
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user