mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
Do not serialize remote objects unless needed
This patch stops serializing console API arguments unless there are listeners of the 'console' event in puppeteer. This saves quite a lot CPU cycles. Fixes #117.
This commit is contained in:
@@ -45,7 +45,7 @@ class Helper {
|
||||
/**
|
||||
* @param {!Connection} client
|
||||
* @param {!Object} remoteObject
|
||||
* @return {!Object}
|
||||
* @return {!Promise<!Object>}
|
||||
*/
|
||||
static async serializeRemoteObject(client, remoteObject) {
|
||||
if (remoteObject.unserializableValue) {
|
||||
@@ -75,9 +75,23 @@ class Helper {
|
||||
// Return description for unserializable object, e.g. 'window'.
|
||||
return remoteObject.description;
|
||||
} finally {
|
||||
client.send('Runtime.releaseObject', {objectId: remoteObject.objectId}).catch(e => {
|
||||
// While we were serializing object, the page might've navigated.
|
||||
});
|
||||
Helper.releaseObject(client, remoteObject);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {!Connection} client
|
||||
* @param {!Object} remoteObject
|
||||
* @return {!Promise}
|
||||
*/
|
||||
static async releaseObject(client, remoteObject) {
|
||||
if (!remoteObject.objectId)
|
||||
return;
|
||||
try {
|
||||
await client.send('Runtime.releaseObject', {objectId: remoteObject.objectId});
|
||||
} catch (e) {
|
||||
// Exceptions might happen in case of a page been navigated or closed.
|
||||
// Swallow these since they are harmless and we don't leak anything in this case.
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user