-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Expand file tree
/
Copy pathDevToolsConnectionAdapter.ts
More file actions
41 lines (33 loc) · 1.22 KB
/
DevToolsConnectionAdapter.ts
File metadata and controls
41 lines (33 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import {ConnectionTransport as DevToolsConnectionTransport} from '../node_modules/chrome-devtools-frontend/front_end/core/protocol_client/ConnectionTransport.js';
import {type ConnectionTransport} from './third_party/index.js';
/**
* Allows a puppeteer {@link ConnectionTransport} to act like a DevTools {@link Connection}.
*/
export class DevToolsConnectionAdapter extends DevToolsConnectionTransport {
#transport: ConnectionTransport | null;
#onDisconnect: ((arg0: string) => void) | null = null;
constructor(transport: ConnectionTransport) {
super();
this.#transport = transport;
this.#transport.onclose = () => this.#onDisconnect?.('');
this.#transport.onmessage = msg => this.onMessage?.(msg);
}
override setOnMessage(onMessage: (arg0: object | string) => void): void {
this.onMessage = onMessage;
}
override setOnDisconnect(onDisconnect: (arg0: string) => void): void {
this.#onDisconnect = onDisconnect;
}
override sendRawMessage(message: string): void {
this.#transport?.send(message);
}
override async disconnect(): Promise<void> {
this.#transport?.close();
this.#transport = null;
}
}