@@ -7,6 +7,7 @@ library debug_session;
77
88import 'dart:async' ;
99import 'dart:convert' ;
10+ import 'dart:html' ;
1011
1112import 'package:built_collection/built_collection.dart' ;
1213import 'package:collection/collection.dart' show IterableExtension;
@@ -43,6 +44,9 @@ const _devToolsAlreadyOpenedAlert =
4344final _debugSessions = < _DebugSession > [];
4445final _tabIdToTrigger = < int , Trigger > {};
4546
47+ // TODO(elliette): Remove once regression is fixed in Chrome.
48+ const _chrome115Error = 'chrome115Error' ;
49+
4650enum DetachReason {
4751 canceledByUser,
4852 connectionErrorEvent,
@@ -114,6 +118,8 @@ Future<void> attachDebugger(
114118
115119 _tabIdToTrigger[dartAppTabId] = trigger;
116120 _registerDebugEventListeners ();
121+ // TODO(elliette): Remove once regression is fixed in Chrome.
122+ _registerChrome115NotificationListeners ();
117123 chrome.debugger.attach (
118124 Debuggee (tabId: dartAppTabId),
119125 '1.3' ,
@@ -424,6 +430,13 @@ void _forwardDwdsEventToChromeDebugger(
424430 final params = messageParams == null
425431 ? < String , Object > {}
426432 : BuiltMap <String , Object >(json.decode (messageParams)).toMap ();
433+
434+ // TODO(elliette): Remove once regression is fixed in Chrome.
435+ if (_shouldSkipEventForChrome115Bug (message.command)) {
436+ _showChrome115ErrorNotification (message.command, tabId);
437+ return ;
438+ }
439+
427440 chrome.debugger.sendCommand (
428441 Debuggee (tabId: tabId),
429442 message.command,
@@ -466,6 +479,52 @@ void _forwardDwdsEventToChromeDebugger(
466479 }
467480}
468481
482+ bool _shouldSkipEventForChrome115Bug (String command) {
483+ final unsupportedOnChrome115 = command.contains ('Debugger.setBreakpoint' ) ||
484+ command.contains ('Debugger.pause' );
485+ if (unsupportedOnChrome115) {
486+ final chromeVersionMatch =
487+ RegExp ('Chrome/([0-9.]+)' ).firstMatch (window.navigator.userAgent);
488+ final chromeVersion = chromeVersionMatch? [0 ];
489+ return chromeVersion? .startsWith ('Chrome/115' ) ?? false ;
490+ }
491+ return false ;
492+ }
493+
494+ void _showChrome115ErrorNotification (String command, int tabId) {
495+ chrome.notifications.create (
496+ // notificationId
497+ '$_chrome115Error -$tabId ' ,
498+ NotificationOptions (
499+ title: '[Error] Dart Debug Extension' ,
500+ message:
501+ 'Regression in Chrome 115 prevents $command . Click here for more details.' ,
502+ iconUrl: 'static_assets/dart.png' ,
503+ type: 'basic' ,
504+ ),
505+ // callback
506+ null ,
507+ );
508+ }
509+
510+ void _registerChrome115NotificationListeners () {
511+ chrome.notifications.onClicked.addListener (
512+ allowInterop ((notificationId) async {
513+ if (notificationId.startsWith (_chrome115Error)) {
514+ final tabId = notificationId.split ('-' )[1 ];
515+ final debugInfo = await fetchStorageObject <DebugInfo >(
516+ type: StorageObject .debugInfo,
517+ tabId: int .parse (tabId),
518+ );
519+ final bugLink = debugInfo? .isInternalBuild ?? false
520+ ? 'https://bugs.chromium.org/p/chromium/issues/detail?id=1469092'
521+ : 'https://github.com/Dart-Code/Dart-Code/issues/4664' ;
522+ await createTab (bugLink);
523+ }
524+ }),
525+ );
526+ }
527+
469528void _forwardChromeDebuggerEventToDwds (
470529 Debuggee source,
471530 String method,
0 commit comments