Skip to content
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: 2 additions & 0 deletions dwds/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
- Include the entire exception description up to the stacktrace in
`mapExceptionStackTrace`.
- Allow enabling experiments in the expression compiler service.
- Include an optional param to `Dwds.start` to indicate whether it a Flutter app
or not.

## 16.0.1

Expand Down
2 changes: 2 additions & 0 deletions dwds/lib/dart_web_debug_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ class Dwds {
SdkConfigurationProvider? sdkConfigurationProvider,
bool emitDebugEvents = true,
bool isInternalBuild = false,
bool isFlutterApp = false,
}) async {
globalLoadStrategy = loadStrategy;
sdkConfigurationProvider ??= DefaultSdkConfigurationProvider();
Expand Down Expand Up @@ -129,6 +130,7 @@ class Dwds {
enableDevtoolsLaunch: enableDevtoolsLaunch,
emitDebugEvents: emitDebugEvents,
isInternalBuild: isInternalBuild,
isFlutterApp: isFlutterApp,
);

final devHandler = DevHandler(
Expand Down
1 change: 1 addition & 0 deletions dwds/lib/data/debug_info.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ abstract class DebugInfo implements Built<DebugInfo, DebugInfoBuilder> {
String? get dwdsVersion;
String? get extensionUrl;
bool? get isInternalBuild;
bool? get isFlutterApp;
}
48 changes: 36 additions & 12 deletions dwds/lib/data/debug_info.g.dart

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

31 changes: 19 additions & 12 deletions dwds/lib/src/handlers/injector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class DwdsInjector {
final bool _useSseForInjectedClient;
final bool _emitDebugEvents;
final bool _isInternalBuild;
final bool _isFlutterApp;

DwdsInjector(
this._loadStrategy, {
Expand All @@ -45,11 +46,13 @@ class DwdsInjector {
bool useSseForInjectedClient = true,
bool emitDebugEvents = true,
bool isInternalBuild = false,
bool isFlutterApp = false,
}) : _extensionUri = extensionUri,
_enableDevtoolsLaunch = enableDevtoolsLaunch,
_useSseForInjectedClient = useSseForInjectedClient,
_emitDebugEvents = emitDebugEvents,
_isInternalBuild = isInternalBuild;
_isInternalBuild = isInternalBuild,
_isFlutterApp = isFlutterApp;

/// Returns the embedded dev handler paths.
///
Expand Down Expand Up @@ -115,6 +118,7 @@ class DwdsInjector {
_enableDevtoolsLaunch,
_emitDebugEvents,
_isInternalBuild,
_isFlutterApp,
);
body += await _loadStrategy.bootstrapFor(entrypoint);
_logger.info('Injected debugging metadata for '
Expand All @@ -140,16 +144,16 @@ class DwdsInjector {
/// Returns the provided body with the main function hoisted into a global
/// variable and a snippet of JS that loads the injected client.
String _injectClientAndHoistMain(
String body,
String appId,
String devHandlerPath,
String entrypointPath,
String? extensionUri,
LoadStrategy loadStrategy,
bool enableDevtoolsLaunch,
bool emitDebugEvents,
bool isInternalBuild,
) {
String body,
String appId,
String devHandlerPath,
String entrypointPath,
String? extensionUri,
LoadStrategy loadStrategy,
bool enableDevtoolsLaunch,
bool emitDebugEvents,
bool isInternalBuild,
bool isFlutterApp) {
final bodyLines = body.split('\n');
final extensionIndex =
bodyLines.indexWhere((line) => line.contains(mainExtensionMarker));
Expand All @@ -169,7 +173,8 @@ String _injectClientAndHoistMain(
loadStrategy,
enableDevtoolsLaunch,
emitDebugEvents,
isInternalBuild);
isInternalBuild,
isFlutterApp);
result += '''
// Injected by dwds for debugging support.
if(!window.\$dwdsInitialized) {
Expand Down Expand Up @@ -204,6 +209,7 @@ String _injectedClientSnippet(
bool enableDevtoolsLaunch,
bool emitDebugEvents,
bool isInternalBuild,
bool isFlutterApp,
) {
var injectedBody = 'window.\$dartAppId = "$appId";\n'
'window.\$dartReloadConfiguration = "${loadStrategy.reloadConfiguration}";\n'
Expand All @@ -215,6 +221,7 @@ String _injectedClientSnippet(
'window.\$dartEntrypointPath = "$entrypointPath";\n'
'window.\$dartEmitDebugEvents = $emitDebugEvents;\n'
'window.\$isInternalBuild = $isInternalBuild;\n'
'window.\$isFlutterApp = $isFlutterApp;\n'
'${loadStrategy.loadClientSnippet(_clientScript)}';
if (extensionUri != null) {
injectedBody += 'window.\$dartExtensionUri = "$extensionUri";\n';
Expand Down
28 changes: 21 additions & 7 deletions dwds/lib/src/injected/client.js

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

6 changes: 6 additions & 0 deletions dwds/test/handlers/injector_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,12 @@ void main() {
expect(result.body, contains('\$isInternalBuild'));
});

test('the injected client contains a global \$isFlutterApp', () async {
final result = await http.get(Uri.parse(
'http://localhost:${server.port}/dwds/src/injected/client.js'));
expect(result.body, contains('\$isFlutterApp'));
});

test('serves the injected client', () async {
final result = await http.get(Uri.parse(
'http://localhost:${server.port}/dwds/src/injected/client.js'));
Expand Down
1 change: 1 addition & 0 deletions dwds/test/puppeteer/extension_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ void main() async {
expect(debugInfo.appOrigin, isNotNull);
expect(debugInfo.appUrl, isNotNull);
expect(debugInfo.isInternalBuild, isNotNull);
expect(debugInfo.isFlutterApp, isNotNull);
await appTab.close();
});

Expand Down
6 changes: 5 additions & 1 deletion dwds/web/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,8 @@ Future<void>? main() {
..appOrigin = window.location.origin
..appUrl = window.location.href
..extensionUrl = windowContext['\$dartExtensionUri']
..isInternalBuild = windowContext['\$isInternalBuild'])));
..isInternalBuild = windowContext['\$isInternalBuild']
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: maybe make consitent with the use below, i.e. r'$dartExtensionUri',r'$isInternalBuild', etc?

..isFlutterApp = windowContext['\$isFlutterApp'])));

dispatchEvent(CustomEvent('dart-app-ready', detail: debugInfoJson));
}, (error, stackTrace) {
Expand Down Expand Up @@ -278,4 +279,7 @@ external set emitRegisterEvent(void Function(String) func);
@JS(r'$isInternalBuild')
external bool get isInternalBuild;

@JS(r'$isFlutterApp')
external bool get isFlutterApp;

bool get _isChromium => window.navigator.vendor.contains('Google');