@@ -78,10 +78,10 @@ export class WebSocketConnection implements ProtocolClient.InspectorBackend.Conn
78
78
#socket: WebSocket | null ;
79
79
onMessage : ( ( arg0 : ( Object | string ) ) => void ) | null ;
80
80
#onDisconnect: ( ( arg0 : string ) => void ) | null ;
81
- #onWebSocketDisconnect: ( ( ) => void ) | null ;
81
+ #onWebSocketDisconnect: ( ( connectionLostDetails ?: { reason ?: string , code ?: string , errorType ?: string } ) => void ) | null ;
82
82
#connected: boolean ;
83
83
#messages: string [ ] ;
84
- constructor ( url : Platform . DevToolsPath . UrlString , onWebSocketDisconnect : ( ) => void ) {
84
+ constructor ( url : Platform . DevToolsPath . UrlString , onWebSocketDisconnect : ( connectionLostDetails ?: { reason ?: string , code ?: string , errorType ?: string } ) => void ) {
85
85
this . #socket = new WebSocket ( url ) ;
86
86
this . #socket. onerror = this . onError . bind ( this ) ;
87
87
this . #socket. onopen = this . onOpen . bind ( this ) ;
@@ -107,9 +107,9 @@ export class WebSocketConnection implements ProtocolClient.InspectorBackend.Conn
107
107
this . #onDisconnect = onDisconnect ;
108
108
}
109
109
110
- private onError ( ) : void {
110
+ private onError ( ev : Event ) : void {
111
111
if ( this . #onWebSocketDisconnect) {
112
- this . #onWebSocketDisconnect. call ( null ) ;
112
+ this . #onWebSocketDisconnect. call ( null , { errorType : ev . type } ) ;
113
113
}
114
114
if ( this . #onDisconnect) {
115
115
// This is called if error occurred while connecting.
@@ -129,9 +129,9 @@ export class WebSocketConnection implements ProtocolClient.InspectorBackend.Conn
129
129
this . #messages = [ ] ;
130
130
}
131
131
132
- private onClose ( ) : void {
132
+ private onClose ( ev : CloseEvent ) : void {
133
133
if ( this . #onWebSocketDisconnect) {
134
- this . #onWebSocketDisconnect. call ( null ) ;
134
+ this . #onWebSocketDisconnect. call ( null , { reason : ev . reason , code : String ( ev . code || 0 ) } ) ;
135
135
}
136
136
if ( this . #onDisconnect) {
137
137
this . #onDisconnect. call ( null , 'websocket closed' ) ;
@@ -264,13 +264,13 @@ export class ParallelConnection implements ParallelConnectionInterface {
264
264
}
265
265
266
266
export async function initMainConnection (
267
- createRootTarget : ( ) => Promise < void > , websocketConnectionLost : ( ) => void ) : Promise < void > {
267
+ createRootTarget : ( ) => Promise < void > , websocketConnectionLost : ( connectionLostDetails ?: { reason ?: string , code ?: string , errorType ?: string } ) => void ) : Promise < void > {
268
268
ProtocolClient . InspectorBackend . Connection . setFactory ( createMainConnection . bind ( null , websocketConnectionLost ) ) ;
269
269
await createRootTarget ( ) ;
270
270
Host . InspectorFrontendHost . InspectorFrontendHostInstance . connectionReady ( ) ;
271
271
}
272
272
273
- function createMainConnection ( websocketConnectionLost : ( ) => void ) : ProtocolClient . InspectorBackend . Connection {
273
+ function createMainConnection ( websocketConnectionLost : ( connectionLostDetails ?: { reason ?: string , code ?: string , errorType ?: string } ) => void ) : ProtocolClient . InspectorBackend . Connection {
274
274
const wsParam = Root . Runtime . Runtime . queryParam ( 'ws' ) ;
275
275
const wssParam = Root . Runtime . Runtime . queryParam ( 'wss' ) ;
276
276
if ( wsParam || wssParam ) {
0 commit comments