From 1a4d09563694324b4d3a8183865ba7561fddbfb2 Mon Sep 17 00:00:00 2001 From: Elliott Brooks <21270878+elliette@users.noreply.github.com> Date: Wed, 2 Aug 2023 15:16:14 -0700 Subject: [PATCH 1/3] Show a warning in Dart debug extension if using a debug command that will cause the page to crash --- dwds/debug_extension_mv3/web/chrome_api.dart | 10 +++ .../web/debug_session.dart | 62 +++++++++++++++++++ 2 files changed, 72 insertions(+) diff --git a/dwds/debug_extension_mv3/web/chrome_api.dart b/dwds/debug_extension_mv3/web/chrome_api.dart index ab7cb831e..20bb95df6 100644 --- a/dwds/debug_extension_mv3/web/chrome_api.dart +++ b/dwds/debug_extension_mv3/web/chrome_api.dart @@ -134,6 +134,16 @@ class Notifications { NotificationOptions options, Function? callback, ); + + external OnClickedHandler get onClicked; +} + +@JS() +@anonymous +class OnClickedHandler { + external void addListener( + void Function(String) callback, + ); } @JS() diff --git a/dwds/debug_extension_mv3/web/debug_session.dart b/dwds/debug_extension_mv3/web/debug_session.dart index 8664f7bc1..097f16899 100644 --- a/dwds/debug_extension_mv3/web/debug_session.dart +++ b/dwds/debug_extension_mv3/web/debug_session.dart @@ -7,6 +7,7 @@ library debug_session; import 'dart:async'; import 'dart:convert'; +import 'dart:html'; import 'package:built_collection/built_collection.dart'; import 'package:collection/collection.dart' show IterableExtension; @@ -43,6 +44,9 @@ const _devToolsAlreadyOpenedAlert = final _debugSessions = <_DebugSession>[]; final _tabIdToTrigger = {}; +// TODO(elliette): Remove once regression is fixed in Chrome. +const _chrome115Error = 'chrome115Error'; + enum DetachReason { canceledByUser, connectionErrorEvent, @@ -114,6 +118,8 @@ Future attachDebugger( _tabIdToTrigger[dartAppTabId] = trigger; _registerDebugEventListeners(); + // TODO(elliette): Remove once regression is fixed in Chrome. + _registerChrome115NotificationListeners(); chrome.debugger.attach( Debuggee(tabId: dartAppTabId), '1.3', @@ -424,6 +430,13 @@ void _forwardDwdsEventToChromeDebugger( final params = messageParams == null ? {} : BuiltMap(json.decode(messageParams)).toMap(); + + // TODO(elliette): Remove once regression is fixed in Chrome. + if (_shouldSkipEventForChrome115Bug(message.command)) { + _showChrome115ErrorNotification(message.command, tabId); + return; + } + chrome.debugger.sendCommand( Debuggee(tabId: tabId), message.command, @@ -466,6 +479,55 @@ void _forwardDwdsEventToChromeDebugger( } } +bool _shouldSkipEventForChrome115Bug(String command) { + final unsupportedOnChrome115 = command.contains('Debugger.setBreakpoint') || + command.contains('Debugger.pause'); + if (unsupportedOnChrome115) { + final chromeVersionMatch = + RegExp('Chrome/([0-9.]+)').firstMatch(window.navigator.userAgent); + final chromeVersion = + chromeVersionMatch == null ? '' : chromeVersionMatch[0]; + if (chromeVersion?.startsWith('Chrome/115') ?? false) { + return true; + } + } + return false; +} + +void _showChrome115ErrorNotification(String command, int tabId) { + chrome.notifications.create( + // notificationId + '$_chrome115Error-$tabId', + NotificationOptions( + title: '[Error] Dart Debug Extension', + message: + 'Regression in Chrome 115 prevents $command. Click here for more details.', + iconUrl: 'static_assets/dart.png', + type: 'basic', + ), + // callback + null, + ); +} + +void _registerChrome115NotificationListeners() { + chrome.notifications.onClicked.addListener( + allowInterop((notificationId) async { + if (notificationId.startsWith(_chrome115Error)) { + final tabId = notificationId.split('-')[1]; + final debugInfo = await fetchStorageObject( + type: StorageObject.debugInfo, + tabId: int.parse(tabId), + ); + final bugLink = debugInfo?.isInternalBuild ?? false + ? 'https://bugs.chromium.org/p/chromium/issues/detail?id=1469092' + : 'https://github.com/Dart-Code/Dart-Code/issues/4664'; + await createTab(bugLink); + } + }), + ); +} + void _forwardChromeDebuggerEventToDwds( Debuggee source, String method, From adc7449c13573f9562941f1d1a08b04f5ae64727 Mon Sep 17 00:00:00 2001 From: Elliott Brooks <21270878+elliette@users.noreply.github.com> Date: Wed, 2 Aug 2023 15:23:24 -0700 Subject: [PATCH 2/3] Update debug extension version --- dwds/debug_extension_mv3/pubspec.yaml | 2 +- dwds/debug_extension_mv3/web/manifest_mv2.json | 9 ++------- dwds/debug_extension_mv3/web/manifest_mv3.json | 2 +- 3 files changed, 4 insertions(+), 9 deletions(-) diff --git a/dwds/debug_extension_mv3/pubspec.yaml b/dwds/debug_extension_mv3/pubspec.yaml index f0421f511..1e0e76e0a 100644 --- a/dwds/debug_extension_mv3/pubspec.yaml +++ b/dwds/debug_extension_mv3/pubspec.yaml @@ -1,6 +1,6 @@ name: mv3_extension publish_to: none -version: 1.34.0 +version: 1.35.0 homepage: https://github.com/dart-lang/webdev description: >- A Chrome extension for Dart debugging. diff --git a/dwds/debug_extension_mv3/web/manifest_mv2.json b/dwds/debug_extension_mv3/web/manifest_mv2.json index 46a4df720..49f78ad4f 100644 --- a/dwds/debug_extension_mv3/web/manifest_mv2.json +++ b/dwds/debug_extension_mv3/web/manifest_mv2.json @@ -1,6 +1,6 @@ { "name": "Dart Debug Extension", - "version": "1.34", + "version": "1.35", "manifest_version": 2, "devtools_page": "static_assets/devtools.html", "browser_action": { @@ -9,12 +9,7 @@ "externally_connectable": { "ids": ["nbkbficgbembimioedhceniahniffgpl"] }, - "permissions": [ - "debugger", - "notifications", - "storage", - "webNavigation" - ], + "permissions": ["debugger", "notifications", "storage", "webNavigation"], "background": { "scripts": ["background.dart.js"] }, diff --git a/dwds/debug_extension_mv3/web/manifest_mv3.json b/dwds/debug_extension_mv3/web/manifest_mv3.json index 38275431b..f73e0e29a 100644 --- a/dwds/debug_extension_mv3/web/manifest_mv3.json +++ b/dwds/debug_extension_mv3/web/manifest_mv3.json @@ -1,6 +1,6 @@ { "name": "Dart Debug Extension", - "version": "1.34", + "version": "1.35", "manifest_version": 3, "devtools_page": "static_assets/devtools.html", "action": { From 54216d429512807b1efceb7de92506868356cbe8 Mon Sep 17 00:00:00 2001 From: Elliott Brooks <21270878+elliette@users.noreply.github.com> Date: Thu, 3 Aug 2023 10:28:05 -0700 Subject: [PATCH 3/3] Respond to PR comments --- dwds/debug_extension_mv3/web/debug_session.dart | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/dwds/debug_extension_mv3/web/debug_session.dart b/dwds/debug_extension_mv3/web/debug_session.dart index 097f16899..310f5b684 100644 --- a/dwds/debug_extension_mv3/web/debug_session.dart +++ b/dwds/debug_extension_mv3/web/debug_session.dart @@ -485,11 +485,8 @@ bool _shouldSkipEventForChrome115Bug(String command) { if (unsupportedOnChrome115) { final chromeVersionMatch = RegExp('Chrome/([0-9.]+)').firstMatch(window.navigator.userAgent); - final chromeVersion = - chromeVersionMatch == null ? '' : chromeVersionMatch[0]; - if (chromeVersion?.startsWith('Chrome/115') ?? false) { - return true; - } + final chromeVersion = chromeVersionMatch?[0]; + return chromeVersion?.startsWith('Chrome/115') ?? false; } return false; }