mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
feat: nicer protocol error messages (#2742)
This patch: - stops appending `undefined` to our protocol messages unnecessarily. - rewrites `Cannot find execution context id` to `Execution context was destroyed, most likely because of a navigation.` when it occurs from a Puppeteer ExecutionContext. The error message is left alone if it occurs via a CDPSession.
This commit is contained in:
committed by
Andrey Lushnikov
parent
9a650c818d
commit
73f9c48081
@@ -64,13 +64,13 @@ class ExecutionContext {
|
||||
if (helper.isString(pageFunction)) {
|
||||
const contextId = this._contextId;
|
||||
const expression = /** @type {string} */ (pageFunction);
|
||||
const { exceptionDetails, result: remoteObject } = await this._client.send('Runtime.evaluate', {
|
||||
const {exceptionDetails, result: remoteObject} = await this._client.send('Runtime.evaluate', {
|
||||
expression,
|
||||
contextId,
|
||||
returnByValue: false,
|
||||
awaitPromise: true,
|
||||
userGesture: true
|
||||
});
|
||||
}).catch(rewriteError);
|
||||
if (exceptionDetails)
|
||||
throw new Error('Evaluation failed: ' + helper.getExceptionMessage(exceptionDetails));
|
||||
return this._objectHandleFactory(remoteObject);
|
||||
@@ -83,7 +83,7 @@ class ExecutionContext {
|
||||
returnByValue: false,
|
||||
awaitPromise: true,
|
||||
userGesture: true
|
||||
});
|
||||
}).catch(rewriteError);
|
||||
if (exceptionDetails)
|
||||
throw new Error('Evaluation failed: ' + helper.getExceptionMessage(exceptionDetails));
|
||||
return this._objectHandleFactory(remoteObject);
|
||||
@@ -116,6 +116,16 @@ class ExecutionContext {
|
||||
}
|
||||
return { value: arg };
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {!Error} error
|
||||
* @return {!Protocol.Runtime.evaluateReturnValue}
|
||||
*/
|
||||
function rewriteError(error) {
|
||||
if (error.message.endsWith('Cannot find context with specified id'))
|
||||
throw new Error('Execution context was destroyed, most likely because of a navigation.');
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user