@@ -13,6 +13,8 @@ import 'package:js/js.dart';
13
13
import 'chrome_api.dart' ;
14
14
import 'debug_session.dart' ;
15
15
import 'logger.dart' ;
16
+ import 'storage.dart' ;
17
+ import 'utils.dart' ;
16
18
17
19
/// Used to identify messages passed to/from Cider.
18
20
///
@@ -25,6 +27,8 @@ const _ciderDartMessageKey = 'CIDER_DART';
25
27
/// Cider extension.
26
28
enum CiderMessageType {
27
29
error,
30
+ inspectorUrlResponse,
31
+ inspectorUrlRequest,
28
32
startDebugResponse,
29
33
startDebugRequest,
30
34
stopDebugResponse,
@@ -113,6 +117,8 @@ Future<void> _handleMessageFromCider(dynamic message, Port _) async {
113
117
await _startDebugging (appId: messageBody);
114
118
} else if (messageType == CiderMessageType .stopDebugRequest.name) {
115
119
await _stopDebugging (appId: messageBody);
120
+ } else if (messageType == CiderMessageType .inspectorUrlRequest.name) {
121
+ await _sendInspectorUrl (appId: messageBody);
116
122
}
117
123
}
118
124
@@ -150,6 +156,45 @@ Future<void> _stopDebugging({String? appId}) async {
150
156
}
151
157
}
152
158
159
+ Future <void > _sendInspectorUrl ({String ? appId}) async {
160
+ if (appId == null ) {
161
+ _sendNoAppIdError ();
162
+ return ;
163
+ }
164
+ final tabId = _tabId (appId);
165
+ final alreadyDebugging = isActiveDebugSession (tabId);
166
+ if (! alreadyDebugging) {
167
+ sendErrorMessageToCider (
168
+ errorType: CiderErrorType .invalidRequest,
169
+ errorDetails:
170
+ 'Cannot send the inspector URL before the debugger has been attached.' ,
171
+ );
172
+ return ;
173
+ }
174
+ final devToolsUri = await fetchStorageObject <String >(
175
+ type: StorageObject .devToolsUri,
176
+ tabId: tabId,
177
+ );
178
+ if (devToolsUri == null ) {
179
+ sendErrorMessageToCider (
180
+ errorType: CiderErrorType .internalError,
181
+ errorDetails: 'Failed to fetch the DevTools URI for the inspector.' ,
182
+ );
183
+ return ;
184
+ }
185
+ final inspectorUrl = addQueryParameters (
186
+ devToolsUri,
187
+ queryParameters: {
188
+ 'embed' : 'true' ,
189
+ 'page' : 'inspector' ,
190
+ },
191
+ );
192
+ sendMessageToCider (
193
+ messageType: CiderMessageType .inspectorUrlResponse,
194
+ messageBody: inspectorUrl,
195
+ );
196
+ }
197
+
153
198
int _tabId (String appId) {
154
199
final tabId = appId.split ('-' ).last;
155
200
return int .parse (tabId);
0 commit comments