Skip to content

[MV3 Debug Extension] Extension sets the ide query parameter for the DevTools URI #1943

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
Feb 8, 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
10 changes: 8 additions & 2 deletions dwds/debug_extension_mv3/web/debug_session.dart
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,8 @@ Future<bool> _connectToDwds({
..instanceId = debugInfo.appInstanceId
..contextId = dartAppContextId
..tabUrl = tabUrl
..uriOnly = true));
..uriOnly = true
..isMv3Extension = true));
return true;
}

Expand Down Expand Up @@ -358,7 +359,12 @@ void _openDevTools(String devToolsUri, {required int dartAppTabId}) async {
final devToolsOpener = await fetchStorageObject<DevToolsOpener>(
type: StorageObject.devToolsOpener);
final devToolsTab = await createTab(
devToolsUri,
addQueryParameters(
devToolsUri,
queryParameters: {
'ide': 'DebugExtension',
},
),
inNewWindow: devToolsOpener?.newWindow ?? false,
);
debugSession.devToolsTabId = devToolsTab.id;
Expand Down
19 changes: 13 additions & 6 deletions dwds/debug_extension_mv3/web/panel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ import 'debug_session.dart';
import 'logger.dart';
import 'messaging.dart';
import 'storage.dart';
import 'utils.dart';

bool connecting = false;
String devToolsBackgroundColor = darkColor;
String backgroundColor = darkColor;
bool isDartApp = true;

const bugLinkId = 'bugLink';
Expand Down Expand Up @@ -148,10 +149,10 @@ void _setColorThemeToMatchChromeDevTools() async {
final chromeTheme = chrome.devtools.panels.themeName;
final panelBody = document.getElementById(panelBodyId);
if (chromeTheme == 'dark') {
devToolsBackgroundColor = darkColor;
backgroundColor = darkColor;
_updateColorThemeForElement(panelBody, isDarkTheme: true);
} else {
devToolsBackgroundColor = lightColor;
backgroundColor = lightColor;
_updateColorThemeForElement(panelBody, isDarkTheme: false);
}
}
Expand Down Expand Up @@ -246,10 +247,16 @@ void _injectDevToolsIframe(String devToolsUri) {
final panelBody = document.getElementById(panelBodyId);
final panelType = panelBody?.getAttribute(panelAttribute) ?? 'debugger';
final iframe = document.createElement('iframe');
iframe.setAttribute(
'src',
'$devToolsUri&embed=true&page=$panelType&backgroundColor=$devToolsBackgroundColor',
final iframeSrc = addQueryParameters(
devToolsUri,
queryParameters: {
'ide': 'ChromeDevTools',
'embed': 'true',
'page': panelType,
'backgroundColor': backgroundColor,
},
);
iframe.setAttribute('src', iframeSrc);
_hideWarningBanner();
_updateElementVisibility(landingPageId, visible: false);
_updateElementVisibility(loadingSpinnerId, visible: false);
Expand Down
12 changes: 12 additions & 0 deletions dwds/debug_extension_mv3/web/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,15 @@ bool isDevMode() {
final extensionName = getProperty(extensionManifest, 'name') ?? '';
return extensionName.contains('DEV');
}

String addQueryParameters(
String uri, {
required Map<String, String> queryParameters,
}) {
final originalUri = Uri.parse(uri);
final newUri = originalUri.replace(queryParameters: {
...originalUri.queryParameters,
...queryParameters,
});
return newUri.toString();
}
13 changes: 10 additions & 3 deletions dwds/lib/data/devtools_request.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,18 @@ abstract class DevToolsRequest
/// correct `dartAppInstanceId` automatically.
String? get tabUrl;

/// If this is a uri only request.
/// Designates this as a request to send back the DevTools URI instead of
/// opening DevTools in a new tab or window.
///
/// Only available on requests coming from dart debug extension.
/// If true, DevTools should open in an embedded Chrome DevTools tab.
/// Only available on requests coming from the Dart Debug Extension. Is `null`
/// for local debug service.
bool? get uriOnly;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious - do they have to be nullable, or can we made them non-nulllable and false by default?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think they make sense to be nullable, since they aren't applicable to non-extension requests. This is the same as tabUrl and contextId (above) which are also null. Added a comment.

/// Whether or not the MV3 Dart Debug Extension sent the request. Is `null`
/// for local debug service.
///
/// Only available on requests coming from the Dart Debug Extension.
bool? get isMv3Extension;
}

/// A response to a [DevToolsRequest].
Expand Down
32 changes: 28 additions & 4 deletions dwds/lib/data/devtools_request.g.dart

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

42 changes: 27 additions & 15 deletions dwds/lib/src/handlers/dev_handler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -544,28 +544,40 @@ class DevHandler {
extensionDebugConnections.add(DebugConnection(appServices));
_servicesByAppId[appId] = appServices;
}
// If we don't have a DevTools instance, then are connecting to an IDE.
// Therefore return early instead of opening DevTools:
if (_devTools == null) return;

final encodedUri = await appServices.debugService.encodedUri;

appServices.dwdsStats.updateLoadTime(
debuggerStart: debuggerStart, devToolsStart: DateTime.now());

if (_devTools != null) {
// If we only want the URI, this means we are embedding Dart DevTools in
// Chrome DevTools. Therefore return early.
if (devToolsRequest.uriOnly ?? false) {
final devToolsUri = _constructDevToolsUri(
encodedUri,
ideQueryParam: 'ChromeDevTools',
);
extensionDebugger.sendEvent('dwds.devtoolsUri', devToolsUri);
return;
}
final devToolsUri = _constructDevToolsUri(
// TODO(elliette): Remove handling requests from the MV2 extension after
// MV3 release.
// If we only want the URI, this means the Dart Debug Extension should
// handle how to open it. Therefore return early before opening a new
// tab or window:
if (devToolsRequest.uriOnly ?? false) {
// The MV3 extension is responsible for adding the IDE query
// parameter to the DevTools URI.
final devToolsUri = (devToolsRequest.isMv3Extension ?? false)
? _constructDevToolsUri(encodedUri)
: _constructDevToolsUri(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can the original extension also add the IDE query parameter, so we don't have to split? Or is it too much change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We would have to do a new release of the old extension, and still handle transition period while it is being released (so there would still be a split). I've added a TODO to remove the old code once the MV3 extension is released.

encodedUri,
ideQueryParam: 'ChromeDevTools',
);
return extensionDebugger.sendEvent('dwds.devtoolsUri', devToolsUri);
}

// Otherwise, launch DevTools in a new tab / window:
await _launchDevTools(
extensionDebugger,
_constructDevToolsUri(
encodedUri,
ideQueryParam: 'DebugExtension',
);
await _launchDevTools(extensionDebugger, devToolsUri);
}
),
);
});
}

Expand Down
22 changes: 17 additions & 5 deletions dwds/lib/src/injected/client.js

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

Loading