From 11843fb8e539b10e364e49cf7b6fe91696dece00 Mon Sep 17 00:00:00 2001 From: Vitali Zaidman Date: Mon, 24 Mar 2025 15:30:46 +0000 Subject: [PATCH] report websocket disconnection reason and code --- front_end/core/host/RNPerfMetrics.ts | 8 +++++--- front_end/core/sdk/Connections.ts | 16 ++++++++-------- .../ui/legacy/RemoteDebuggingTerminatedScreen.ts | 9 ++++++--- .../components/utils/TargetDetachedDialog.ts | 4 ++-- 4 files changed, 21 insertions(+), 16 deletions(-) diff --git a/front_end/core/host/RNPerfMetrics.ts b/front_end/core/host/RNPerfMetrics.ts index 233bd8f60fc..07ab177b56d 100644 --- a/front_end/core/host/RNPerfMetrics.ts +++ b/front_end/core/host/RNPerfMetrics.ts @@ -142,8 +142,8 @@ class RNPerfMetrics { }); } - remoteDebuggingTerminated(reason: string): void { - this.sendEvent({eventName: 'Connection.DebuggingTerminated', params: {reason}}); + remoteDebuggingTerminated(params: {reason?: string, code?: string, errorType?: string} = {}): void { + this.sendEvent({eventName: 'Connection.DebuggingTerminated', params}); } developerResourceLoadingStarted(parsedURL: ParsedURL, loadingMethod: DeveloperResourceLoaded): void { @@ -333,7 +333,9 @@ export type BrowserErrorEvent = Readonly<{ export type RemoteDebuggingTerminatedEvent = Readonly<{ eventName: 'Connection.DebuggingTerminated', params: Readonly<{ - reason: string, + reason?: string, + code?: string, + errorType?: string, }>, }>; diff --git a/front_end/core/sdk/Connections.ts b/front_end/core/sdk/Connections.ts index 3d5a959fd35..9613a6fbd1c 100644 --- a/front_end/core/sdk/Connections.ts +++ b/front_end/core/sdk/Connections.ts @@ -78,10 +78,10 @@ export class WebSocketConnection implements ProtocolClient.InspectorBackend.Conn #socket: WebSocket|null; onMessage: ((arg0: (Object|string)) => void)|null; #onDisconnect: ((arg0: string) => void)|null; - #onWebSocketDisconnect: (() => void)|null; + #onWebSocketDisconnect: ((connectionLostDetails?: {reason?: string, code?: string, errorType?: string}) => void)|null; #connected: boolean; #messages: string[]; - constructor(url: Platform.DevToolsPath.UrlString, onWebSocketDisconnect: () => void) { + constructor(url: Platform.DevToolsPath.UrlString, onWebSocketDisconnect: (connectionLostDetails?: {reason?: string, code?: string, errorType?: string}) => void) { this.#socket = new WebSocket(url); this.#socket.onerror = this.onError.bind(this); this.#socket.onopen = this.onOpen.bind(this); @@ -107,9 +107,9 @@ export class WebSocketConnection implements ProtocolClient.InspectorBackend.Conn this.#onDisconnect = onDisconnect; } - private onError(): void { + private onError(ev: Event): void { if (this.#onWebSocketDisconnect) { - this.#onWebSocketDisconnect.call(null); + this.#onWebSocketDisconnect.call(null, {errorType: ev.type}); } if (this.#onDisconnect) { // This is called if error occurred while connecting. @@ -129,9 +129,9 @@ export class WebSocketConnection implements ProtocolClient.InspectorBackend.Conn this.#messages = []; } - private onClose(): void { + private onClose(ev: CloseEvent): void { if (this.#onWebSocketDisconnect) { - this.#onWebSocketDisconnect.call(null); + this.#onWebSocketDisconnect.call(null, {reason: ev.reason, code: String(ev.code || 0)}); } if (this.#onDisconnect) { this.#onDisconnect.call(null, 'websocket closed'); @@ -264,13 +264,13 @@ export class ParallelConnection implements ParallelConnectionInterface { } export async function initMainConnection( - createRootTarget: () => Promise, websocketConnectionLost: () => void): Promise { + createRootTarget: () => Promise, websocketConnectionLost: (connectionLostDetails?: {reason?: string, code?: string, errorType?: string}) => void): Promise { ProtocolClient.InspectorBackend.Connection.setFactory(createMainConnection.bind(null, websocketConnectionLost)); await createRootTarget(); Host.InspectorFrontendHost.InspectorFrontendHostInstance.connectionReady(); } -function createMainConnection(websocketConnectionLost: () => void): ProtocolClient.InspectorBackend.Connection { +function createMainConnection(websocketConnectionLost: (connectionLostDetails?: {reason?: string, code?: string, errorType?: string}) => void): ProtocolClient.InspectorBackend.Connection { const wsParam = Root.Runtime.Runtime.queryParam('ws'); const wssParam = Root.Runtime.Runtime.queryParam('wss'); if (wsParam || wssParam) { diff --git a/front_end/ui/legacy/RemoteDebuggingTerminatedScreen.ts b/front_end/ui/legacy/RemoteDebuggingTerminatedScreen.ts index 78f1f61d602..d9f8b74792a 100644 --- a/front_end/ui/legacy/RemoteDebuggingTerminatedScreen.ts +++ b/front_end/ui/legacy/RemoteDebuggingTerminatedScreen.ts @@ -102,13 +102,16 @@ export class RemoteDebuggingTerminatedScreen extends VBox { ); } - static show(reason: string): void { + static show( + uiMessage: string, + connectionLostDetails?: {reason?: string, code?: string, errorType?: string} + ): void { const dialog = new Dialog('remote-debnugging-terminated'); dialog.setSizeBehavior(SizeBehavior.MeasureContent); dialog.setDimmed(true); - new RemoteDebuggingTerminatedScreen(reason, () => dialog.hide()).show(dialog.contentElement); + new RemoteDebuggingTerminatedScreen(uiMessage, () => dialog.hide()).show(dialog.contentElement); dialog.show(); - Host.rnPerfMetrics.remoteDebuggingTerminated(reason); + Host.rnPerfMetrics.remoteDebuggingTerminated(connectionLostDetails); } #createFeedbackSection(feedbackLink: string): LitHtml.TemplateResult { diff --git a/front_end/ui/legacy/components/utils/TargetDetachedDialog.ts b/front_end/ui/legacy/components/utils/TargetDetachedDialog.ts index 50193cb219f..da499434aff 100644 --- a/front_end/ui/legacy/components/utils/TargetDetachedDialog.ts +++ b/front_end/ui/legacy/components/utils/TargetDetachedDialog.ts @@ -33,9 +33,9 @@ export class TargetDetachedDialog extends SDK.SDKModel.SDKModel implements UI.RemoteDebuggingTerminatedScreen.RemoteDebuggingTerminatedScreen.show(reason); } - static webSocketConnectionLost(): void { + static webSocketConnectionLost(connectionLostDetails?: {reason?: string, code?: string, errorType?: string}): void { UI.RemoteDebuggingTerminatedScreen.RemoteDebuggingTerminatedScreen.show( - i18nString(UIStrings.websocketDisconnected)); + i18nString(UIStrings.websocketDisconnected), connectionLostDetails); } targetCrashed(): void {