Skip to content

Commit 26e19a4

Browse files
authored
report websocket disconnection reason and code (#156)
1 parent 46feed4 commit 26e19a4

File tree

4 files changed

+21
-16
lines changed

4 files changed

+21
-16
lines changed

front_end/core/host/RNPerfMetrics.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,8 @@ class RNPerfMetrics {
142142
});
143143
}
144144

145-
remoteDebuggingTerminated(reason: string): void {
146-
this.sendEvent({eventName: 'Connection.DebuggingTerminated', params: {reason}});
145+
remoteDebuggingTerminated(params: {reason?: string, code?: string, errorType?: string} = {}): void {
146+
this.sendEvent({eventName: 'Connection.DebuggingTerminated', params});
147147
}
148148

149149
developerResourceLoadingStarted(parsedURL: ParsedURL, loadingMethod: DeveloperResourceLoaded): void {
@@ -333,7 +333,9 @@ export type BrowserErrorEvent = Readonly<{
333333
export type RemoteDebuggingTerminatedEvent = Readonly<{
334334
eventName: 'Connection.DebuggingTerminated',
335335
params: Readonly<{
336-
reason: string,
336+
reason?: string,
337+
code?: string,
338+
errorType?: string,
337339
}>,
338340
}>;
339341

front_end/core/sdk/Connections.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,10 @@ export class WebSocketConnection implements ProtocolClient.InspectorBackend.Conn
7878
#socket: WebSocket|null;
7979
onMessage: ((arg0: (Object|string)) => void)|null;
8080
#onDisconnect: ((arg0: string) => void)|null;
81-
#onWebSocketDisconnect: (() => void)|null;
81+
#onWebSocketDisconnect: ((connectionLostDetails?: {reason?: string, code?: string, errorType?: string}) => void)|null;
8282
#connected: boolean;
8383
#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) {
8585
this.#socket = new WebSocket(url);
8686
this.#socket.onerror = this.onError.bind(this);
8787
this.#socket.onopen = this.onOpen.bind(this);
@@ -107,9 +107,9 @@ export class WebSocketConnection implements ProtocolClient.InspectorBackend.Conn
107107
this.#onDisconnect = onDisconnect;
108108
}
109109

110-
private onError(): void {
110+
private onError(ev: Event): void {
111111
if (this.#onWebSocketDisconnect) {
112-
this.#onWebSocketDisconnect.call(null);
112+
this.#onWebSocketDisconnect.call(null, {errorType: ev.type});
113113
}
114114
if (this.#onDisconnect) {
115115
// This is called if error occurred while connecting.
@@ -129,9 +129,9 @@ export class WebSocketConnection implements ProtocolClient.InspectorBackend.Conn
129129
this.#messages = [];
130130
}
131131

132-
private onClose(): void {
132+
private onClose(ev: CloseEvent): void {
133133
if (this.#onWebSocketDisconnect) {
134-
this.#onWebSocketDisconnect.call(null);
134+
this.#onWebSocketDisconnect.call(null, {reason: ev.reason, code: String(ev.code || 0)});
135135
}
136136
if (this.#onDisconnect) {
137137
this.#onDisconnect.call(null, 'websocket closed');
@@ -264,13 +264,13 @@ export class ParallelConnection implements ParallelConnectionInterface {
264264
}
265265

266266
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> {
268268
ProtocolClient.InspectorBackend.Connection.setFactory(createMainConnection.bind(null, websocketConnectionLost));
269269
await createRootTarget();
270270
Host.InspectorFrontendHost.InspectorFrontendHostInstance.connectionReady();
271271
}
272272

273-
function createMainConnection(websocketConnectionLost: () => void): ProtocolClient.InspectorBackend.Connection {
273+
function createMainConnection(websocketConnectionLost: (connectionLostDetails?: {reason?: string, code?: string, errorType?: string}) => void): ProtocolClient.InspectorBackend.Connection {
274274
const wsParam = Root.Runtime.Runtime.queryParam('ws');
275275
const wssParam = Root.Runtime.Runtime.queryParam('wss');
276276
if (wsParam || wssParam) {

front_end/ui/legacy/RemoteDebuggingTerminatedScreen.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,16 @@ export class RemoteDebuggingTerminatedScreen extends VBox {
102102
);
103103
}
104104

105-
static show(reason: string): void {
105+
static show(
106+
uiMessage: string,
107+
connectionLostDetails?: {reason?: string, code?: string, errorType?: string}
108+
): void {
106109
const dialog = new Dialog('remote-debnugging-terminated');
107110
dialog.setSizeBehavior(SizeBehavior.MeasureContent);
108111
dialog.setDimmed(true);
109-
new RemoteDebuggingTerminatedScreen(reason, () => dialog.hide()).show(dialog.contentElement);
112+
new RemoteDebuggingTerminatedScreen(uiMessage, () => dialog.hide()).show(dialog.contentElement);
110113
dialog.show();
111-
Host.rnPerfMetrics.remoteDebuggingTerminated(reason);
114+
Host.rnPerfMetrics.remoteDebuggingTerminated(connectionLostDetails);
112115
}
113116

114117
#createFeedbackSection(feedbackLink: string): LitHtml.TemplateResult {

front_end/ui/legacy/components/utils/TargetDetachedDialog.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ export class TargetDetachedDialog extends SDK.SDKModel.SDKModel<void> implements
3333
UI.RemoteDebuggingTerminatedScreen.RemoteDebuggingTerminatedScreen.show(reason);
3434
}
3535

36-
static webSocketConnectionLost(): void {
36+
static webSocketConnectionLost(connectionLostDetails?: {reason?: string, code?: string, errorType?: string}): void {
3737
UI.RemoteDebuggingTerminatedScreen.RemoteDebuggingTerminatedScreen.show(
38-
i18nString(UIStrings.websocketDisconnected));
38+
i18nString(UIStrings.websocketDisconnected), connectionLostDetails);
3939
}
4040

4141
targetCrashed(): void {

0 commit comments

Comments
 (0)