diff --git a/dwds/CHANGELOG.md b/dwds/CHANGELOG.md index 60ada03d9..00798899f 100644 --- a/dwds/CHANGELOG.md +++ b/dwds/CHANGELOG.md @@ -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 diff --git a/dwds/lib/dart_web_debug_service.dart b/dwds/lib/dart_web_debug_service.dart index d609e643b..ba66a8272 100644 --- a/dwds/lib/dart_web_debug_service.dart +++ b/dwds/lib/dart_web_debug_service.dart @@ -87,6 +87,7 @@ class Dwds { SdkConfigurationProvider? sdkConfigurationProvider, bool emitDebugEvents = true, bool isInternalBuild = false, + bool isFlutterApp = false, }) async { globalLoadStrategy = loadStrategy; sdkConfigurationProvider ??= DefaultSdkConfigurationProvider(); @@ -129,6 +130,7 @@ class Dwds { enableDevtoolsLaunch: enableDevtoolsLaunch, emitDebugEvents: emitDebugEvents, isInternalBuild: isInternalBuild, + isFlutterApp: isFlutterApp, ); final devHandler = DevHandler( diff --git a/dwds/lib/data/debug_info.dart b/dwds/lib/data/debug_info.dart index 41ac51b39..288d1e7b5 100644 --- a/dwds/lib/data/debug_info.dart +++ b/dwds/lib/data/debug_info.dart @@ -22,4 +22,5 @@ abstract class DebugInfo implements Built { String? get dwdsVersion; String? get extensionUrl; bool? get isInternalBuild; + bool? get isFlutterApp; } diff --git a/dwds/lib/data/debug_info.g.dart b/dwds/lib/data/debug_info.g.dart index 6fb126599..e3b1f4135 100644 --- a/dwds/lib/data/debug_info.g.dart +++ b/dwds/lib/data/debug_info.g.dart @@ -75,6 +75,13 @@ class _$DebugInfoSerializer implements StructuredSerializer { ..add( serializers.serialize(value, specifiedType: const FullType(bool))); } + value = object.isFlutterApp; + if (value != null) { + result + ..add('isFlutterApp') + ..add( + serializers.serialize(value, specifiedType: const FullType(bool))); + } return result; } @@ -121,6 +128,10 @@ class _$DebugInfoSerializer implements StructuredSerializer { result.isInternalBuild = serializers.deserialize(value, specifiedType: const FullType(bool)) as bool?; break; + case 'isFlutterApp': + result.isFlutterApp = serializers.deserialize(value, + specifiedType: const FullType(bool)) as bool?; + break; } } @@ -145,6 +156,8 @@ class _$DebugInfo extends DebugInfo { final String? extensionUrl; @override final bool? isInternalBuild; + @override + final bool? isFlutterApp; factory _$DebugInfo([void Function(DebugInfoBuilder)? updates]) => (new DebugInfoBuilder()..update(updates))._build(); @@ -157,7 +170,8 @@ class _$DebugInfo extends DebugInfo { this.appUrl, this.dwdsVersion, this.extensionUrl, - this.isInternalBuild}) + this.isInternalBuild, + this.isFlutterApp}) : super._(); @override @@ -178,7 +192,8 @@ class _$DebugInfo extends DebugInfo { appUrl == other.appUrl && dwdsVersion == other.dwdsVersion && extensionUrl == other.extensionUrl && - isInternalBuild == other.isInternalBuild; + isInternalBuild == other.isInternalBuild && + isFlutterApp == other.isFlutterApp; } @override @@ -189,14 +204,16 @@ class _$DebugInfo extends DebugInfo { $jc( $jc( $jc( - $jc($jc(0, appEntrypointPath.hashCode), - appId.hashCode), - appInstanceId.hashCode), - appOrigin.hashCode), - appUrl.hashCode), - dwdsVersion.hashCode), - extensionUrl.hashCode), - isInternalBuild.hashCode)); + $jc( + $jc($jc(0, appEntrypointPath.hashCode), + appId.hashCode), + appInstanceId.hashCode), + appOrigin.hashCode), + appUrl.hashCode), + dwdsVersion.hashCode), + extensionUrl.hashCode), + isInternalBuild.hashCode), + isFlutterApp.hashCode)); } @override @@ -209,7 +226,8 @@ class _$DebugInfo extends DebugInfo { ..add('appUrl', appUrl) ..add('dwdsVersion', dwdsVersion) ..add('extensionUrl', extensionUrl) - ..add('isInternalBuild', isInternalBuild)) + ..add('isInternalBuild', isInternalBuild) + ..add('isFlutterApp', isFlutterApp)) .toString(); } } @@ -252,6 +270,10 @@ class DebugInfoBuilder implements Builder { set isInternalBuild(bool? isInternalBuild) => _$this._isInternalBuild = isInternalBuild; + bool? _isFlutterApp; + bool? get isFlutterApp => _$this._isFlutterApp; + set isFlutterApp(bool? isFlutterApp) => _$this._isFlutterApp = isFlutterApp; + DebugInfoBuilder(); DebugInfoBuilder get _$this { @@ -265,6 +287,7 @@ class DebugInfoBuilder implements Builder { _dwdsVersion = $v.dwdsVersion; _extensionUrl = $v.extensionUrl; _isInternalBuild = $v.isInternalBuild; + _isFlutterApp = $v.isFlutterApp; _$v = null; } return this; @@ -294,7 +317,8 @@ class DebugInfoBuilder implements Builder { appUrl: appUrl, dwdsVersion: dwdsVersion, extensionUrl: extensionUrl, - isInternalBuild: isInternalBuild); + isInternalBuild: isInternalBuild, + isFlutterApp: isFlutterApp); replace(_$result); return _$result; } diff --git a/dwds/lib/src/handlers/injector.dart b/dwds/lib/src/handlers/injector.dart index 2f572cfef..b486cc058 100644 --- a/dwds/lib/src/handlers/injector.dart +++ b/dwds/lib/src/handlers/injector.dart @@ -37,6 +37,7 @@ class DwdsInjector { final bool _useSseForInjectedClient; final bool _emitDebugEvents; final bool _isInternalBuild; + final bool _isFlutterApp; DwdsInjector( this._loadStrategy, { @@ -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. /// @@ -115,6 +118,7 @@ class DwdsInjector { _enableDevtoolsLaunch, _emitDebugEvents, _isInternalBuild, + _isFlutterApp, ); body += await _loadStrategy.bootstrapFor(entrypoint); _logger.info('Injected debugging metadata for ' @@ -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)); @@ -169,7 +173,8 @@ String _injectClientAndHoistMain( loadStrategy, enableDevtoolsLaunch, emitDebugEvents, - isInternalBuild); + isInternalBuild, + isFlutterApp); result += ''' // Injected by dwds for debugging support. if(!window.\$dwdsInitialized) { @@ -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' @@ -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'; diff --git a/dwds/lib/src/injected/client.js b/dwds/lib/src/injected/client.js index d2b487866..b38e397a7 100644 --- a/dwds/lib/src/injected/client.js +++ b/dwds/lib/src/injected/client.js @@ -8156,7 +8156,7 @@ }, _$DebugInfoSerializer: function _$DebugInfoSerializer() { }, - _$DebugInfo: function _$DebugInfo(t0, t1, t2, t3, t4, t5, t6, t7) { + _$DebugInfo: function _$DebugInfo(t0, t1, t2, t3, t4, t5, t6, t7, t8) { var _ = this; _.appEntrypointPath = t0; _.appId = t1; @@ -8166,10 +8166,11 @@ _.dwdsVersion = t5; _.extensionUrl = t6; _.isInternalBuild = t7; + _.isFlutterApp = t8; }, DebugInfoBuilder: function DebugInfoBuilder() { var _ = this; - _._isInternalBuild = _._extensionUrl = _._dwdsVersion = _._appUrl = _._appOrigin = _._appInstanceId = _._appId = _._appEntrypointPath = _._$v = null; + _._isFlutterApp = _._isInternalBuild = _._extensionUrl = _._dwdsVersion = _._appUrl = _._appOrigin = _._appInstanceId = _._appId = _._appEntrypointPath = _._$v = null; }, DevToolsRequest: function DevToolsRequest() { }, @@ -22544,6 +22545,11 @@ result.push("isInternalBuild"); result.push(serializers.serialize$2$specifiedType(value, B.FullType_MtR)); } + value = object.isFlutterApp; + if (value != null) { + result.push("isFlutterApp"); + result.push(serializers.serialize$2$specifiedType(value, B.FullType_MtR)); + } return result; }, serialize$2(serializers, object) { @@ -22592,6 +22598,10 @@ t1 = A._asBoolQ(serializers.deserialize$2$specifiedType(value, B.FullType_MtR)); result.get$_$this()._isInternalBuild = t1; break; + case "isFlutterApp": + t1 = A._asBoolQ(serializers.deserialize$2$specifiedType(value, B.FullType_MtR)); + result.get$_$this()._isFlutterApp = t1; + break; } } return result._debug_info$_build$0(); @@ -22615,11 +22625,11 @@ return false; if (other === _this) return true; - return other instanceof A.DebugInfo && _this.appEntrypointPath == other.appEntrypointPath && _this.appId == other.appId && _this.appInstanceId == other.appInstanceId && _this.appOrigin == other.appOrigin && _this.appUrl == other.appUrl && _this.dwdsVersion == other.dwdsVersion && _this.extensionUrl == other.extensionUrl && _this.isInternalBuild == other.isInternalBuild; + return other instanceof A.DebugInfo && _this.appEntrypointPath == other.appEntrypointPath && _this.appId == other.appId && _this.appInstanceId == other.appInstanceId && _this.appOrigin == other.appOrigin && _this.appUrl == other.appUrl && _this.dwdsVersion == other.dwdsVersion && _this.extensionUrl == other.extensionUrl && _this.isInternalBuild == other.isInternalBuild && _this.isFlutterApp == other.isFlutterApp; }, get$hashCode(_) { var _this = this; - return A.$jf(A.$jc(A.$jc(A.$jc(A.$jc(A.$jc(A.$jc(A.$jc(A.$jc(0, J.get$hashCode$(_this.appEntrypointPath)), J.get$hashCode$(_this.appId)), J.get$hashCode$(_this.appInstanceId)), J.get$hashCode$(_this.appOrigin)), J.get$hashCode$(_this.appUrl)), J.get$hashCode$(_this.dwdsVersion)), J.get$hashCode$(_this.extensionUrl)), J.get$hashCode$(_this.isInternalBuild))); + return A.$jf(A.$jc(A.$jc(A.$jc(A.$jc(A.$jc(A.$jc(A.$jc(A.$jc(A.$jc(0, J.get$hashCode$(_this.appEntrypointPath)), J.get$hashCode$(_this.appId)), J.get$hashCode$(_this.appInstanceId)), J.get$hashCode$(_this.appOrigin)), J.get$hashCode$(_this.appUrl)), J.get$hashCode$(_this.dwdsVersion)), J.get$hashCode$(_this.extensionUrl)), J.get$hashCode$(_this.isInternalBuild)), J.get$hashCode$(_this.isFlutterApp))); }, toString$0(_) { var _this = this, @@ -22633,6 +22643,7 @@ t2.add$2(t1, "dwdsVersion", _this.dwdsVersion); t2.add$2(t1, "extensionUrl", _this.extensionUrl); t2.add$2(t1, "isInternalBuild", _this.isInternalBuild); + t2.add$2(t1, "isFlutterApp", _this.isFlutterApp); return t2.toString$0(t1); } }; @@ -22649,6 +22660,7 @@ _this._dwdsVersion = $$v.dwdsVersion; _this._extensionUrl = $$v.extensionUrl; _this._isInternalBuild = $$v.isInternalBuild; + _this._isFlutterApp = $$v.isFlutterApp; _this._$v = null; } return _this; @@ -22657,7 +22669,7 @@ var _this = this, _$result = _this._$v; if (_$result == null) - _$result = new A._$DebugInfo(_this.get$_$this()._appEntrypointPath, _this.get$_$this()._appId, _this.get$_$this()._appInstanceId, _this.get$_$this()._appOrigin, _this.get$_$this()._appUrl, _this.get$_$this()._dwdsVersion, _this.get$_$this()._extensionUrl, _this.get$_$this()._isInternalBuild); + _$result = new A._$DebugInfo(_this.get$_$this()._appEntrypointPath, _this.get$_$this()._appId, _this.get$_$this()._appInstanceId, _this.get$_$this()._appOrigin, _this.get$_$this()._appUrl, _this.get$_$this()._dwdsVersion, _this.get$_$this()._extensionUrl, _this.get$_$this()._isInternalBuild, _this.get$_$this()._isFlutterApp); A.ArgumentError_checkNotNull(_$result, "other", type$.DebugInfo); return _this._$v = _$result; } @@ -25187,8 +25199,10 @@ b.get$_$this()._appUrl = t2; t2 = A._asStringQ(t1.$index(0, "$dartExtensionUri")); b.get$_$this()._extensionUrl = t2; - t1 = A._asBoolQ(t1.$index(0, "$isInternalBuild")); - b.get$_$this()._isInternalBuild = t1; + t2 = A._asBoolQ(t1.$index(0, "$isInternalBuild")); + b.get$_$this()._isInternalBuild = t2; + t1 = A._asBoolQ(t1.$index(0, "$isFlutterApp")); + b.get$_$this()._isFlutterApp = t1; return b; }, $signature: 77 diff --git a/dwds/test/handlers/injector_test.dart b/dwds/test/handlers/injector_test.dart index 103551e6d..d0bd68b58 100644 --- a/dwds/test/handlers/injector_test.dart +++ b/dwds/test/handlers/injector_test.dart @@ -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')); diff --git a/dwds/test/puppeteer/extension_test.dart b/dwds/test/puppeteer/extension_test.dart index 768ebe481..07afb95d5 100644 --- a/dwds/test/puppeteer/extension_test.dart +++ b/dwds/test/puppeteer/extension_test.dart @@ -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(); }); diff --git a/dwds/web/client.dart b/dwds/web/client.dart index bd1eb2cab..1b1b4b309 100644 --- a/dwds/web/client.dart +++ b/dwds/web/client.dart @@ -181,7 +181,8 @@ Future? main() { ..appOrigin = window.location.origin ..appUrl = window.location.href ..extensionUrl = windowContext['\$dartExtensionUri'] - ..isInternalBuild = windowContext['\$isInternalBuild']))); + ..isInternalBuild = windowContext['\$isInternalBuild'] + ..isFlutterApp = windowContext['\$isFlutterApp']))); dispatchEvent(CustomEvent('dart-app-ready', detail: debugInfoJson)); }, (error, stackTrace) { @@ -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');