Skip to content

Commit 6aa6cc2

Browse files
committed
allow displaying custom errors to the user for when devtools is disconnected
1 parent c3a792f commit 6aa6cc2

File tree

2 files changed

+34
-4
lines changed

2 files changed

+34
-4
lines changed

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

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,21 @@ const UIStrings = {
1313
*@description Text on the remote debugging window to indicate the connection is lost
1414
*/
1515
websocketDisconnected: 'WebSocket disconnected',
16+
/**
17+
*@description Text on the remote debugging window to indicate the connection cannot be made because the device is not connected
18+
*/
19+
websocketDisconnectedUnregisteredDevice: 'The corresponding app for this DevTools session cannot be found. Please relaunch DevTools from the terminal.',
20+
/**
21+
*@description Text on the remote debugging window to indicate the connection to corresponding device was lost
22+
*/
23+
websocketDisconnectedConnectionLost: 'Connection lost to corresponding device'
1624
};
25+
26+
const DisconnectedReasonsUIStrings = {
27+
UREGISTERED_DEVICE: UIStrings.websocketDisconnectedUnregisteredDevice,
28+
CONNECTION_LOST: UIStrings.websocketDisconnectedConnectionLost
29+
}
30+
1731
const str_ = i18n.i18n.registerUIStrings('ui/legacy/components/utils/TargetDetachedDialog.ts', UIStrings);
1832
const i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_);
1933
export class TargetDetachedDialog extends SDK.SDKModel.SDKModel<void> implements ProtocolProxyApi.InspectorDispatcher {
@@ -33,9 +47,25 @@ export class TargetDetachedDialog extends SDK.SDKModel.SDKModel<void> implements
3347
UI.RemoteDebuggingTerminatedScreen.RemoteDebuggingTerminatedScreen.show(reason);
3448
}
3549

50+
static getCustomUiReason(connectionLostDetails?: {reason?: string, code?: string, errorType?: string}): string | null {
51+
if (!connectionLostDetails) {
52+
return null;
53+
}
54+
55+
if (connectionLostDetails.code === "1011" && connectionLostDetails.reason?.includes('[UREGISTERED_DEVICE]')) {
56+
return i18nString(DisconnectedReasonsUIStrings.UREGISTERED_DEVICE);
57+
}
58+
59+
if (connectionLostDetails.code === "1000" && connectionLostDetails.reason?.includes('[CONNECTION_LOST]')) {
60+
return i18nString(DisconnectedReasonsUIStrings.CONNECTION_LOST);
61+
}
62+
63+
return null;
64+
}
65+
3666
static webSocketConnectionLost(connectionLostDetails?: {reason?: string, code?: string, errorType?: string}): void {
37-
UI.RemoteDebuggingTerminatedScreen.RemoteDebuggingTerminatedScreen.show(
38-
i18nString(UIStrings.websocketDisconnected), connectionLostDetails);
67+
const uiReason = TargetDetachedDialog.getCustomUiReason(connectionLostDetails) || i18nString(UIStrings.websocketDisconnected);
68+
UI.RemoteDebuggingTerminatedScreen.RemoteDebuggingTerminatedScreen.show(uiReason, connectionLostDetails);
3969
}
4070

4171
targetCrashed(): void {

front_end/ui/legacy/remoteDebuggingTerminatedScreen.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
.widget {
88
padding: 20px;
9-
user-select: all;
9+
user-select: text;
1010
}
1111

1212
.remote-debugging-terminated-title {
@@ -26,7 +26,6 @@
2626
grid-template-columns: 1fr auto;
2727
grid-gap: 8px;
2828
align-items: center;
29-
padding-top: 12px;
3029
}
3130

3231
.remote-debugging-terminated-label {
@@ -48,6 +47,7 @@
4847
padding: 12px 16px;
4948
background-color: var(--color-background-elevation-1);
5049
border-radius: 6px;
50+
margin-bottom: 12px;
5151
}
5252

5353
.remote-debugging-terminated-feedback-label {

0 commit comments

Comments
 (0)