Skip to content

Dart Debug Extension: don't forward events to Chrome that will cause a crash #2179

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dwds/debug_extension_mv3/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
10 changes: 10 additions & 0 deletions dwds/debug_extension_mv3/web/chrome_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
59 changes: 59 additions & 0 deletions dwds/debug_extension_mv3/web/debug_session.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -43,6 +44,9 @@ const _devToolsAlreadyOpenedAlert =
final _debugSessions = <_DebugSession>[];
final _tabIdToTrigger = <int, Trigger>{};

// TODO(elliette): Remove once regression is fixed in Chrome.
const _chrome115Error = 'chrome115Error';

enum DetachReason {
canceledByUser,
connectionErrorEvent,
Expand Down Expand Up @@ -114,6 +118,8 @@ Future<void> attachDebugger(

_tabIdToTrigger[dartAppTabId] = trigger;
_registerDebugEventListeners();
// TODO(elliette): Remove once regression is fixed in Chrome.
_registerChrome115NotificationListeners();
chrome.debugger.attach(
Debuggee(tabId: dartAppTabId),
'1.3',
Expand Down Expand Up @@ -424,6 +430,13 @@ void _forwardDwdsEventToChromeDebugger(
final params = messageParams == null
? <String, Object>{}
: BuiltMap<String, Object>(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,
Expand Down Expand Up @@ -466,6 +479,52 @@ 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?[0];
return chromeVersion?.startsWith('Chrome/115') ?? false;
}
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<DebugInfo>(
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,
Expand Down
9 changes: 2 additions & 7 deletions dwds/debug_extension_mv3/web/manifest_mv2.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand All @@ -9,12 +9,7 @@
"externally_connectable": {
"ids": ["nbkbficgbembimioedhceniahniffgpl"]
},
"permissions": [
"debugger",
"notifications",
"storage",
"webNavigation"
],
"permissions": ["debugger", "notifications", "storage", "webNavigation"],
"background": {
"scripts": ["background.dart.js"]
},
Expand Down
2 changes: 1 addition & 1 deletion dwds/debug_extension_mv3/web/manifest_mv3.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Dart Debug Extension",
"version": "1.34",
"version": "1.35",
"manifest_version": 3,
"devtools_page": "static_assets/devtools.html",
"action": {
Expand Down