mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
fix(eval): be able to throw protocol like errors (#4551)
This commit is contained in:
committed by
Andrey Lushnikov
parent
6a50888d34
commit
b2f94909a1
@@ -42,18 +42,10 @@ class ExecutionContext {
|
||||
/**
|
||||
* @param {Function|string} pageFunction
|
||||
* @param {...*} args
|
||||
* @return {!Promise<(!Object|undefined)>}
|
||||
* @return {!Promise<*>}
|
||||
*/
|
||||
async evaluate(pageFunction, ...args) {
|
||||
try {
|
||||
return await this._evaluateInternal(true /* returnByValue */, pageFunction, ...args);
|
||||
} catch (error) {
|
||||
if (error.message.includes('Object reference chain is too long'))
|
||||
return;
|
||||
if (error.message.includes('Object couldn\'t be returned by value'))
|
||||
return;
|
||||
throw error;
|
||||
}
|
||||
return await this._evaluateInternal(true /* returnByValue */, pageFunction, ...args);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -66,9 +58,10 @@ class ExecutionContext {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {boolean} returnByValue
|
||||
* @param {Function|string} pageFunction
|
||||
* @param {...*} args
|
||||
* @return {!Promise<!JSHandle>}
|
||||
* @return {!Promise<*>}
|
||||
*/
|
||||
async _evaluateInternal(returnByValue, pageFunction, ...args) {
|
||||
const suffix = `//# sourceURL=${EVALUATION_SCRIPT_URL}`;
|
||||
@@ -165,6 +158,11 @@ class ExecutionContext {
|
||||
* @return {!Protocol.Runtime.evaluateReturnValue}
|
||||
*/
|
||||
function rewriteError(error) {
|
||||
if (error.message.includes('Object reference chain is too long'))
|
||||
return {result: {type: 'undefined'}};
|
||||
if (error.message.includes('Object couldn\'t be returned by value'))
|
||||
return {result: {type: 'undefined'}};
|
||||
|
||||
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