From e36ce8bee18b4a8c7bf4c0692269d0095d186d06 Mon Sep 17 00:00:00 2001 From: Alex Rudenko Date: Wed, 12 Jun 2024 13:49:16 +0200 Subject: [PATCH] fix: connection closed error should be a rejected promise (#12575) --- packages/puppeteer-core/src/cdp/Connection.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/puppeteer-core/src/cdp/Connection.ts b/packages/puppeteer-core/src/cdp/Connection.ts index 05eb6ba9a30..60a1c63cfd6 100644 --- a/packages/puppeteer-core/src/cdp/Connection.ts +++ b/packages/puppeteer-core/src/cdp/Connection.ts @@ -18,7 +18,6 @@ import type {ConnectionTransport} from '../common/ConnectionTransport.js'; import {debug} from '../common/Debug.js'; import {TargetCloseError} from '../common/Errors.js'; import {EventEmitter} from '../common/EventEmitter.js'; -import {assert} from '../util/assert.js'; import {createProtocolErrorMessage} from '../util/ErrorLike.js'; import {CdpCDPSession} from './CDPSession.js'; @@ -120,8 +119,9 @@ export class Connection extends EventEmitter { sessionId?: string, options?: CommandOptions ): Promise { - assert(!this.#closed, 'Protocol error: Connection closed.'); - + if (this.#closed) { + return Promise.reject(new Error('Protocol error: Connection closed.')); + } return callbacks.create(method, options?.timeout ?? this.#timeout, id => { const stringifiedMessage = JSON.stringify({ method,