File tree Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Original file line number Diff line number Diff line change 1+ /**
2+ * @license
3+ * Copyright 2025 Google LLC
4+ * SPDX-License-Identifier: Apache-2.0
5+ */
6+
7+ import { type ConnectionTransport } from 'puppeteer-core' ;
8+ import { Connection } from '../node_modules/chrome-devtools-frontend/front_end/core/protocol_client/InspectorBackend.js' ;
9+
10+ /**
11+ * Allows a puppeteer {@link ConnectionTransport} to act like a DevTools {@link Connection}.
12+ */
13+ class DevToolsConnectionAdapter extends Connection {
14+ #transport: ConnectionTransport | null ;
15+ #onDisconnect: ( ( arg0 : string ) => void ) | null = null ;
16+
17+ constructor ( transport : ConnectionTransport ) {
18+ super ( ) ;
19+ this . #transport = transport ;
20+ this . #transport. onclose = ( ) => this . #onDisconnect?.( '' ) ;
21+ this . #transport. onmessage = ( msg ) => this . onMessage ?.( msg ) ;
22+ }
23+
24+ override setOnMessage ( onMessage : ( arg0 : Object | string ) => void ) : void {
25+ this . onMessage = onMessage ;
26+ }
27+
28+ override setOnDisconnect ( onDisconnect : ( arg0 : string ) => void ) : void {
29+ this . #onDisconnect = onDisconnect ;
30+ }
31+
32+ override sendRawMessage ( message : string ) : void {
33+ this . #transport?. send ( message ) ;
34+ }
35+
36+ override async disconnect ( ) : Promise < void > {
37+ this . #transport?. close ( ) ;
38+ this . #transport = null ;
39+ }
40+ }
You can’t perform that action at this time.
0 commit comments