Skip to content

Commit 0ec210d

Browse files
committed
allow displaying custom errors to the user for when devtools is disconnected
1 parent a0331f5 commit 0ec210d

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

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

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,16 @@ 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+
websocketDisconnectedNonRegisteredDevice: 'The corresponding application for this instance of DevTools cannot be found. Please re-lauch DevTools from the terminal.',
1620
};
21+
22+
const DisconnectedReasonsUIStrings = {
23+
NON_REGISTERED_DEVICE: UIStrings.websocketDisconnectedNonRegisteredDevice
24+
}
25+
1726
const str_ = i18n.i18n.registerUIStrings('ui/legacy/components/utils/TargetDetachedDialog.ts', UIStrings);
1827
const i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_);
1928
export class TargetDetachedDialog extends SDK.SDKModel.SDKModel<void> implements ProtocolProxyApi.InspectorDispatcher {
@@ -33,9 +42,21 @@ export class TargetDetachedDialog extends SDK.SDKModel.SDKModel<void> implements
3342
UI.RemoteDebuggingTerminatedScreen.RemoteDebuggingTerminatedScreen.show(reason);
3443
}
3544

45+
static getCustomUiReason(connectionLostDetails?: {reason?: string, code?: string, errorType?: string}): string | null {
46+
if (!connectionLostDetails) {
47+
return null;
48+
}
49+
50+
if (connectionLostDetails.code === "1011" && connectionLostDetails.reason?.includes('[NON_REGISTERED_DEVICE]')) {
51+
return i18nString(DisconnectedReasonsUIStrings.NON_REGISTERED_DEVICE);
52+
}
53+
54+
return null;
55+
}
56+
3657
static webSocketConnectionLost(connectionLostDetails?: {reason?: string, code?: string, errorType?: string}): void {
37-
UI.RemoteDebuggingTerminatedScreen.RemoteDebuggingTerminatedScreen.show(
38-
i18nString(UIStrings.websocketDisconnected), connectionLostDetails);
58+
const uiReason = TargetDetachedDialog.getCustomUiReason(connectionLostDetails) || i18nString(UIStrings.websocketDisconnected);
59+
UI.RemoteDebuggingTerminatedScreen.RemoteDebuggingTerminatedScreen.show(uiReason, connectionLostDetails);
3960
}
4061

4162
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)