Skip to content

Report WebSocket connection termination error code and message #156

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions front_end/core/host/RNPerfMetrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
}>,
}>;

Expand Down
16 changes: 8 additions & 8 deletions front_end/core/sdk/Connections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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.
Expand All @@ -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');
Expand Down Expand Up @@ -264,13 +264,13 @@ export class ParallelConnection implements ParallelConnectionInterface {
}

export async function initMainConnection(
createRootTarget: () => Promise<void>, websocketConnectionLost: () => void): Promise<void> {
createRootTarget: () => Promise<void>, websocketConnectionLost: (connectionLostDetails?: {reason?: string, code?: string, errorType?: string}) => void): Promise<void> {
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) {
Expand Down
9 changes: 6 additions & 3 deletions front_end/ui/legacy/RemoteDebuggingTerminatedScreen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions front_end/ui/legacy/components/utils/TargetDetachedDialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ export class TargetDetachedDialog extends SDK.SDKModel.SDKModel<void> 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 {
Expand Down
Loading