From 28a8d0ffb6345309df2bb23c9a5e2bd8be2f059d Mon Sep 17 00:00:00 2001 From: Nikolay Vitkov <34244704+Lightning00Blade@users.noreply.github.com> Date: Mon, 29 Apr 2024 08:27:16 +0200 Subject: [PATCH] fix(cdp): throw on closed connection (#12352) --- packages/puppeteer-core/src/cdp/Connection.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/puppeteer-core/src/cdp/Connection.ts b/packages/puppeteer-core/src/cdp/Connection.ts index 3c565341b38..9495650f7b5 100644 --- a/packages/puppeteer-core/src/cdp/Connection.ts +++ b/packages/puppeteer-core/src/cdp/Connection.ts @@ -18,6 +18,7 @@ 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'; @@ -117,6 +118,8 @@ export class Connection extends EventEmitter { sessionId?: string, options?: CommandOptions ): Promise { + assert(!this.#closed, 'Protocol error: Connection closed.'); + return callbacks.create(method, options?.timeout ?? this.#timeout, id => { const stringifiedMessage = JSON.stringify({ method,