Skip to content

Can debug with the MV3 Dart Debug Extension #1802

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 10 commits into from
Nov 30, 2022
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
5 changes: 5 additions & 0 deletions dwds/debug_extension_mv3/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,20 @@ environment:

dependencies:
built_value: ^8.3.0
collection: ^1.15.0
js: ^0.6.1+1

dev_dependencies:
build: ^2.0.0
build_runner: ^2.0.6
built_collection: ^5.0.0
built_value_generator: ^8.3.0
build_web_compilers: ^3.0.0
dwds: ^16.0.0

dependency_overrides:
dwds:
path: ..
# TODO(elliette): Remove override once package:sse is published.
sse:
path: /Users/elliottbrooks/dev/sse
25 changes: 4 additions & 21 deletions dwds/debug_extension_mv3/web/background.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import 'package:dwds/data/debug_info.dart';
import 'package:dwds/data/extension_request.dart';
import 'package:js/js.dart';

import 'debug_session.dart';
import 'chrome_api.dart';
import 'data_types.dart';
import 'lifeline_ports.dart';
import 'logger.dart';
import 'messaging.dart';
Expand Down Expand Up @@ -59,10 +59,8 @@ Future<void> _startDebugSession(Tab currentTab) async {
if (!isAuthenticated) return;

maybeCreateLifelinePort(currentTab.id);
final devToolsOpener = await fetchStorageObject<DevToolsOpener>(
type: StorageObject.devToolsOpener);
await _createTab('https://dart.dev/',
inNewWindow: devToolsOpener?.newWindow ?? false);
registerDebugEventListeners();
attachDebugger(tabId);
}

Future<bool> _authenticateUser(String extensionUrl, int tabId) async {
Expand All @@ -73,7 +71,7 @@ Future<bool> _authenticateUser(String extensionUrl, int tabId) async {
debugError('Not authenticated: ${response.status} / $responseBody',
verbose: true);
_showWarningNotification('Please re-authenticate and try again.');
await _createTab(authUrl, inNewWindow: false);
await createTab(authUrl, inNewWindow: false);
return false;
}
return true;
Expand Down Expand Up @@ -159,18 +157,3 @@ Future<Tab?> _getTab() async {
final tabs = List<Tab>.from(await promiseToFuture(chrome.tabs.query(query)));
return tabs.isNotEmpty ? tabs.first : null;
}

Future<Tab> _createTab(String url, {bool inNewWindow = false}) async {
if (inNewWindow) {
final windowPromise = chrome.windows.create(
WindowInfo(focused: true, url: url),
);
final windowObj = await promiseToFuture<WindowObj>(windowPromise);
return windowObj.tabs.first;
}
final tabPromise = chrome.tabs.create(TabInfo(
active: true,
url: url,
));
return promiseToFuture<Tab>(tabPromise);
}
55 changes: 55 additions & 0 deletions dwds/debug_extension_mv3/web/chrome_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ external Chrome get chrome;
@anonymous
class Chrome {
external Action get action;
external Debugger get debugger;
external Notifications get notifications;
external Runtime get runtime;
external Scripting get scripting;
Expand Down Expand Up @@ -43,6 +44,48 @@ class IconInfo {
external factory IconInfo({String path});
}

/// chrome.debugger APIs:
/// https://developer.chrome.com/docs/extensions/reference/debugger

@JS()
@anonymous
class Debugger {
external void attach(
Debuggee target, String requiredVersion, Function? callback);

external void detach(Debuggee target, Function? callback);

external void sendCommand(Debuggee target, String method,
Object? commandParams, Function? callback);

external OnDetachHandler get onDetach;

external OnEventHandler get onEvent;
}

@JS()
@anonymous
class OnDetachHandler {
external void addListener(
void Function(Debuggee source, String reason) callback);
}

@JS()
@anonymous
class OnEventHandler {
external void addListener(
void Function(Debuggee source, String method, Object? params) callback);
}

@JS()
@anonymous
class Debuggee {
external int get tabId;
external String get extensionId;
external String get targetId;
external factory Debuggee({int tabId, String? extensionId, String? targetId});
}

/// chrome.notification APIs:
/// https://developer.chrome.com/docs/extensions/reference/notifications

Expand Down Expand Up @@ -77,11 +120,19 @@ class Runtime {

external Object getManifest();

// Note: Not checking the lastError when one occurs throws a runtime exception.
external ChromeError? get lastError;

external ConnectionHandler get onConnect;

external OnMessageHandler get onMessage;
}

@JS()
class ChromeError {
external String get message;
}

@JS()
@anonymous
class ConnectInfo {
Expand Down Expand Up @@ -179,6 +230,10 @@ class Tabs {

external Object create(TabInfo tabInfo);

external Object get(int tabId);

external Object remove(int tabId);

external OnActivatedHandler get onActivated;

external OnRemovedHandler get onRemoved;
Expand Down
8 changes: 8 additions & 0 deletions dwds/debug_extension_mv3/web/data_serializers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,24 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'package:built_collection/built_collection.dart';
import 'package:built_value/serializer.dart';
import 'package:dwds/data/debug_info.dart';
import 'package:dwds/data/devtools_request.dart';
import 'package:dwds/data/extension_request.dart';

import 'data_types.dart';

part 'data_serializers.g.dart';

/// Serializers for all the data types used in the Dart Debug Extension.
@SerializersFor([
BatchedEvents,
DebugInfo,
DevToolsOpener,
DevToolsRequest,
ExtensionEvent,
ExtensionRequest,
ExtensionResponse,
])
final Serializers serializers = _$serializers;
10 changes: 9 additions & 1 deletion dwds/debug_extension_mv3/web/data_serializers.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading