Skip to content

Commit 8c667e8

Browse files
authored
Dart Debug Extension: don't forward events to Chrome that will cause a crash (#2179)
1 parent db1f552 commit 8c667e8

File tree

5 files changed

+73
-9
lines changed

5 files changed

+73
-9
lines changed

dwds/debug_extension_mv3/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: mv3_extension
22
publish_to: none
3-
version: 1.34.0
3+
version: 1.35.0
44
homepage: https://github.com/dart-lang/webdev
55
description: >-
66
A Chrome extension for Dart debugging.

dwds/debug_extension_mv3/web/chrome_api.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,16 @@ class Notifications {
134134
NotificationOptions options,
135135
Function? callback,
136136
);
137+
138+
external OnClickedHandler get onClicked;
139+
}
140+
141+
@JS()
142+
@anonymous
143+
class OnClickedHandler {
144+
external void addListener(
145+
void Function(String) callback,
146+
);
137147
}
138148

139149
@JS()

dwds/debug_extension_mv3/web/debug_session.dart

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ library debug_session;
77

88
import 'dart:async';
99
import 'dart:convert';
10+
import 'dart:html';
1011

1112
import 'package:built_collection/built_collection.dart';
1213
import 'package:collection/collection.dart' show IterableExtension;
@@ -43,6 +44,9 @@ const _devToolsAlreadyOpenedAlert =
4344
final _debugSessions = <_DebugSession>[];
4445
final _tabIdToTrigger = <int, Trigger>{};
4546

47+
// TODO(elliette): Remove once regression is fixed in Chrome.
48+
const _chrome115Error = 'chrome115Error';
49+
4650
enum 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+
469528
void _forwardChromeDebuggerEventToDwds(
470529
Debuggee source,
471530
String method,

dwds/debug_extension_mv3/web/manifest_mv2.json

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "Dart Debug Extension",
3-
"version": "1.34",
3+
"version": "1.35",
44
"manifest_version": 2,
55
"devtools_page": "static_assets/devtools.html",
66
"browser_action": {
@@ -9,12 +9,7 @@
99
"externally_connectable": {
1010
"ids": ["nbkbficgbembimioedhceniahniffgpl"]
1111
},
12-
"permissions": [
13-
"debugger",
14-
"notifications",
15-
"storage",
16-
"webNavigation"
17-
],
12+
"permissions": ["debugger", "notifications", "storage", "webNavigation"],
1813
"background": {
1914
"scripts": ["background.dart.js"]
2015
},

dwds/debug_extension_mv3/web/manifest_mv3.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "Dart Debug Extension",
3-
"version": "1.34",
3+
"version": "1.35",
44
"manifest_version": 3,
55
"devtools_page": "static_assets/devtools.html",
66
"action": {

0 commit comments

Comments
 (0)