@@ -7,6 +7,7 @@ library debug_session;
7
7
8
8
import 'dart:async' ;
9
9
import 'dart:convert' ;
10
+ import 'dart:html' ;
10
11
11
12
import 'package:built_collection/built_collection.dart' ;
12
13
import 'package:collection/collection.dart' show IterableExtension;
@@ -43,6 +44,9 @@ const _devToolsAlreadyOpenedAlert =
43
44
final _debugSessions = < _DebugSession > [];
44
45
final _tabIdToTrigger = < int , Trigger > {};
45
46
47
+ // TODO(elliette): Remove once regression is fixed in Chrome.
48
+ const _chrome115Error = 'chrome115Error' ;
49
+
46
50
enum DetachReason {
47
51
canceledByUser,
48
52
connectionErrorEvent,
@@ -114,6 +118,8 @@ Future<void> attachDebugger(
114
118
115
119
_tabIdToTrigger[dartAppTabId] = trigger;
116
120
_registerDebugEventListeners ();
121
+ // TODO(elliette): Remove once regression is fixed in Chrome.
122
+ _registerChrome115NotificationListeners ();
117
123
chrome.debugger.attach (
118
124
Debuggee (tabId: dartAppTabId),
119
125
'1.3' ,
@@ -424,6 +430,13 @@ void _forwardDwdsEventToChromeDebugger(
424
430
final params = messageParams == null
425
431
? < String , Object > {}
426
432
: 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
+
427
440
chrome.debugger.sendCommand (
428
441
Debuggee (tabId: tabId),
429
442
message.command,
@@ -466,6 +479,52 @@ void _forwardDwdsEventToChromeDebugger(
466
479
}
467
480
}
468
481
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
+
469
528
void _forwardChromeDebuggerEventToDwds (
470
529
Debuggee source,
471
530
String method,
0 commit comments