From 705811fee2172b0f4bae1112a20901c731acb39c Mon Sep 17 00:00:00 2001 From: Gary Roumanis Date: Thu, 7 Jan 2021 15:49:09 -0800 Subject: [PATCH] Fix launching DevTools with Flutter Web applications (#72110) --- .../lib/src/isolated/resident_web_runner.dart | 11 +++++++++++ packages/flutter_tools/lib/src/vmservice.dart | 10 +++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/packages/flutter_tools/lib/src/isolated/resident_web_runner.dart b/packages/flutter_tools/lib/src/isolated/resident_web_runner.dart index c320c3e7cf..5b501760e2 100644 --- a/packages/flutter_tools/lib/src/isolated/resident_web_runner.dart +++ b/packages/flutter_tools/lib/src/isolated/resident_web_runner.dart @@ -808,6 +808,11 @@ class _ResidentWebRunner extends ResidentWebRunner { }); websocketUri = Uri.parse(_connectionResult.debugConnection.uri); + device.vmService = _vmService; + // Update caches to enable the FlutterVmService extensions. + setHttpAddress(_httpUriFromWebsocketUri(websocketUri), device.vmService); + setWsAddress(websocketUri, device.vmService); + // Always run main after connecting because start paused doesn't work yet. if (!debuggingOptions.startPaused || !supportsServiceProtocol) { _connectionResult.appConnection.runMain(); @@ -859,4 +864,10 @@ class _ResidentWebRunner extends ResidentWebRunner { await device.exitApps(); appFinished(); } + + Uri _httpUriFromWebsocketUri(Uri websocketUri) { + const String wsPath = '/ws'; + final String path = websocketUri.path; + return websocketUri.replace(scheme: 'http', path: path.substring(0, path.length - wsPath.length)); + } } diff --git a/packages/flutter_tools/lib/src/vmservice.dart b/packages/flutter_tools/lib/src/vmservice.dart index 1e8acae81e..ef5e4aafbb 100644 --- a/packages/flutter_tools/lib/src/vmservice.dart +++ b/packages/flutter_tools/lib/src/vmservice.dart @@ -3,7 +3,7 @@ // found in the LICENSE file. import 'package:file/file.dart'; -import 'package:meta/meta.dart' show required, visibleForTesting; +import 'package:meta/meta.dart' show required; import 'package:vm_service/vm_service.dart' as vm_service; import 'base/context.dart'; @@ -152,13 +152,17 @@ final Expando _httpAddressExpando = Expando(); final Expando _wsAddressExpando = Expando(); -@visibleForTesting void setHttpAddress(Uri uri, vm_service.VmService vmService) { + if(vmService == null) { + return; + } _httpAddressExpando[vmService] = uri; } -@visibleForTesting void setWsAddress(Uri uri, vm_service.VmService vmService) { + if(vmService == null) { + return; + } _wsAddressExpando[vmService] = uri; }