@@ -13,6 +13,8 @@ import 'package:js/js.dart';
1313import 'chrome_api.dart' ;
1414import 'debug_session.dart' ;
1515import 'logger.dart' ;
16+ import 'storage.dart' ;
17+ import 'utils.dart' ;
1618
1719/// Used to identify messages passed to/from Cider.
1820///
@@ -25,6 +27,8 @@ const _ciderDartMessageKey = 'CIDER_DART';
2527/// Cider extension.
2628enum CiderMessageType {
2729 error,
30+ inspectorUrlResponse,
31+ inspectorUrlRequest,
2832 startDebugResponse,
2933 startDebugRequest,
3034 stopDebugResponse,
@@ -113,6 +117,8 @@ Future<void> _handleMessageFromCider(dynamic message, Port _) async {
113117 await _startDebugging (appId: messageBody);
114118 } else if (messageType == CiderMessageType .stopDebugRequest.name) {
115119 await _stopDebugging (appId: messageBody);
120+ } else if (messageType == CiderMessageType .inspectorUrlRequest.name) {
121+ await _sendInspectorUrl (appId: messageBody);
116122 }
117123}
118124
@@ -150,6 +156,45 @@ Future<void> _stopDebugging({String? appId}) async {
150156 }
151157}
152158
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+
153198int _tabId (String appId) {
154199 final tabId = appId.split ('-' ).last;
155200 return int .parse (tabId);
0 commit comments