diff --git a/packages/puppeteer-core/src/common/Connection.ts b/packages/puppeteer-core/src/common/Connection.ts index 65eaa65fa05..05888f0f337 100644 --- a/packages/puppeteer-core/src/common/Connection.ts +++ b/packages/puppeteer-core/src/common/Connection.ts @@ -160,9 +160,16 @@ export class CallbackRegistry { errorMessage: string | ProtocolError, originalMessage?: string ): void { - const isError = errorMessage instanceof ProtocolError; - const message = isError ? errorMessage.message : errorMessage; - const error = isError ? errorMessage : callback.error; + let error: ProtocolError; + let message: string; + if (errorMessage instanceof ProtocolError) { + error = errorMessage; + error.cause = callback.error; + message = errorMessage.message; + } else { + error = callback.error; + message = errorMessage; + } callback.reject( rewriteError(