fix(cdp): throw on closed connection (#12352)

This commit is contained in:
Nikolay Vitkov 2024-04-29 08:27:16 +02:00 committed by GitHub
parent 914c107216
commit 28a8d0ffb6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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<CDPSessionEvents> {
sessionId?: string,
options?: CommandOptions
): Promise<ProtocolMapping.Commands[T]['returnType']> {
assert(!this.#closed, 'Protocol error: Connection closed.');
return callbacks.create(method, options?.timeout ?? this.#timeout, id => {
const stringifiedMessage = JSON.stringify({
method,