[flutter_tools][web] flutter drive -d chrome hangs before WebDriver starts
- Dominant language
- Dart
- Stars
- 179k
- Forks
- 31.1k
- PR merge metrics
- PR metrics pending
Description
### Steps to reproduce
1. Use Flutter 3.47.2 (`d3b14c876900e553bc736ca19295fc09e3853e8e`).
2. Create the files from the code sample below and run `flutter pub get`.
3. Use Chrome and ChromeDriver with the same major version. This reproduction uses Chrome for Testing 150.0.7871.114.
4. Start ChromeDriver in one terminal:
```console
/path/to/chromedriver --port=4444 --verbose
```
5. Run the integration test in another terminal:
```console
flutter drive \
--driver=test_driver/integration_test.dart \
--target=integration_test/app_test.dart \
--device-id=chrome \
--browser-name=chrome \
--chrome-binary="/path/to/Google Chrome for Testing" \
--driver-port=4444 \
--no-headless \
--verbose
```
6. Observe that no Chrome window opens. The command does not exit.
7. Stop the command and change only `--device-id=chrome` to `--device-id=web-server`.
8. Run it again. One visible Chrome window opens, the button is clicked, and the test passes.
This started in our application after upgrading from Flutter 3.44.8
(`058e0af2c2b57e369d905a03ac9748b0ebf543c6`) to Flutter 3.47.2. Our full web
integration suite passed on 3.44.8 and hangs on 3.47.2. The minimal sample
below reproduces the hang on 3.47.2.
The relevant change is [PR #185481](https://github.com/flutter/flutter/pull/185481) by @temoorx,
merged as [`4d5e75f`](https://github.com/flutter/flutter/commit/4d5e75f4bc979dcd55a0cdbf77efb458fc332901).
That commit is present in Flutter 3.47.0 and 3.47.2, but not in 3.44.8.
### Expected results
`flutter drive -d chrome` should start the web server, let WebDriver open the
selected Chrome binary, run the integration test, and exit. With
`--no-headless`, one visible WebDriver-controlled Chrome window should open.
### Actual results
`flutter drive -d chrome` compiles and syncs the app, but no Chrome window
opens. The command then waits forever. ChromeDriver receives no session
request, so changing ChromeDriver versions does not affect the result.
`flutter run -d chrome` works because that command still launches Chrome
directly. `flutter drive -d web-server --no-headless` also works because
WebDriver opens the visible Chrome window after the web server is ready.
The 3.47.2 source has a deterministic startup cycle:
1. [`DriveCommand`](https://github.com/flutter/flutter/blob/d3b14c876900e553bc736ca19295fc09e3853e8e/packages/flutter_tools/lib/src/commands/drive.dart#L343-L366) awaits `driverService.start()` before it calls `startTest()`.
2. It passes `no-launch-chrome: true` for web devices.
3. [`ChromiumDevice.startApp`](https://github.com/flutter/flutter/blob/d3b14c876900e553bc736ca19295fc09e3853e8e/packages/flutter_tools/lib/src/web/web_device.dart#L138-L150) therefore does not call `chromeLauncher.launch()`.
4. [`ResidentWebRunner.attach`](https://github.com/flutter/flutter/blob/d3b14c876900e553bc736ca19295fc09e3853e8e/packages/flutter_tools/lib/src/isolated/resident_web_runner.dart#L800-L824) still awaits `ChromiumLauncher.connectedInstance` because the selected device is a `ChromiumDevice`.
5. [`WebDriverService.startTest`](https://github.com/flutter/flutter/blob/d3b14c876900e553bc736ca19295fc09e3853e8e/packages/flutter_tools/lib/src/drive/web_driver_service.dart#L152-L209) creates the WebDriver session, but `DriveCommand` cannot reach it until `start()` returns.
The same cycle is still present on current `main` at
`c77a5798c59f0643bc835c12d473924fd0206cc5`.
One possible fix is to skip the `connectedInstance` wait when
`no-launch-chrome` is true. The existing debug connection can then wait for
the browser that `startTest()` opens through WebDriver. A full command-lifecycle
test would cover the ordering that the regression test in PR #185481 missed.
### Code sample
Code sample
`pubspec.yaml`:
```yaml
name: flutter_drive_chrome_hang_repro
publish_to: none
environment:
sdk: ^3.13.2
dependencies:
flutter:
sdk: flutter
dev_dependencies:
flutter_test:
sdk: flutter
integration_test:
sdk: flutter
flutter:
uses-material-design: true
```
`lib/main.dart`:
```dart
import 'package:flutter/material.dart';
void main() {
runApp(const ReproApp());
}
class ReproApp extends StatelessWidget {
const ReproApp({super.key});
@override
Widget build(BuildContext context) {
return const MaterialApp(
debugShowCheckedModeBanner: false,
home: CounterScreen(),
);
}
}
class CounterScreen extends StatefulWidget {
const CounterScreen({super.key});
@override
State createState() => _CounterScreenState();
}
class _CounterScreenState extends State {
var count = 0;
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text('Count: $count', key: const ValueKey('count')),
const SizedBox(height: 16),
ElevatedButton(
key: const ValueKey('increment'),
onPressed: () => setState(() => count++),
child: const Text('Increment'),
),
],
),
),
);
}
}
```
`integration_test/app_test.dart`:
```dart
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
import 'package:flutter_drive_chrome_hang_repro/main.dart';
void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
testWidgets('increments the counter', (tester) async {
await tester.pumpWidget(const ReproApp());
expect(find.text('Count: 0'), findsOneWidget);
await tester.tap(find.byKey(const ValueKey('increment')));
await tester.pumpAndSettle();
expect(find.text('Count: 1'), findsOneWidget);
});
}
```
`test_driver/integration_test.dart`:
```dart
import 'package:integration_test/integration_test_driver.dart';
Future main() => integrationDriver();
```
### Screenshots or Video
Screenshots / Video demonstration
Not applicable. The failing command does not open a browser window. The
`web-server` mitigation opens a visible browser and completes the test.
### Logs
Logs
The `-d chrome` Flutter log ends here. It produced no more output for 40
seconds before I interrupted it:
```console
[ +33 ms] Launching integration_test/app_test.dart on Chrome in debug mode...
[ +30 ms] Waiting for connection from debug service on Chrome...
[+5276 ms] Waiting for connection from debug service on Chrome... (completed in 10.5s)
[ ] Synced 84.9MB.
[ ] <- accept
[ ] Caching compiled dill
```
Its isolated verbose ChromeDriver log contains only these three lines. It
received no command:
```console
[1788225754.226][INFO]: Starting ChromeDriver 150.0.7871.114 (f405107495a07cb1bfcf687d4af8d91117098db6-refs/branch-heads/7871@{#2955}) on port 4446
[1788225754.226][INFO]: Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
[1788225754.230][INFO]: ChromeDriver was started successfully on port 4446
```
Changing only the device to `web-server` opens the visible browser and passes:
```console
[ +30 ms] Launching integration_test/app_test.dart on Web Server in debug mode...
[ +30 ms] Waiting for connection from debug service on Web Server...
[+4599 ms] Waiting for connection from debug service on Web Server... (completed in 10.0s)
[ ] Synced 84.9MB.
[ +14 ms] integration_test/app_test.dart is being served at http://localhost:17972
[ +7 ms] Debug service listening on ws://127.0.0.1:54907/Xu7DK0pOwpk=/ws
[+1159 ms] All tests passed.
[ +79 ms] Application finished.
[ ] "flutter drive" took 15,631ms.
[ ] exiting with code 0
```
### Flutter Doctor output
Doctor output
```console
[!] Flutter (Channel [user-branch], 3.47.2, on macOS 26.6.2 25G83 darwin-arm64, locale en-US) [1,032ms]
! Flutter version 3.47.2 on channel [user-branch] at /Users/andrewcoutts/Projects/flutter
Currently on an unknown channel. Run `flutter channel` to switch to an official channel.
• Upstream repository git@github.com:flutter/flutter.git
• Framework revision d3b14c8769 (5 days ago), 2026-08-26 16:07:51 -0700
• Engine revision a804b26164
• Dart version 3.13.2
• DevTools version 2.60.0
• Feature flags: enable-web, enable-linux-desktop, enable-macos-desktop, enable-windows-desktop, enable-android, enable-ios, cli-animations, enable-native-assets, enable-record-use, enable-swift-package-manager, omit-legacy-version-file, enable-lldb-debugging, enable-uiscene-migration, enable-riscv64
[✓] Android toolchain - develop for Android devices (Android SDK version 36.1.0) [1,741ms]
• Android SDK at /Users/andrewcoutts/Library/Android/sdk
• Platform android-37.0, build-tools 36.1.0
• Java version OpenJDK Runtime Environment (build 21.0.8+-14018985-b1038.68)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 26.6) [1,519ms]
• Xcode at /Applications/Xcode.app/Contents/Developer
• Build 17F113
• CocoaPods version 1.16.2
[✓] Chrome - develop for the web [4ms]
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Connected device (6 available) [6.0s]
• sdk gphone64 arm64 (mobile) • emulator-5554 • android-arm64 • Android 16 (API 36) (emulator)
• sdk gphone64 arm64 (mobile) • emulator-5556 • android-arm64 • Android 16 (API 36) (emulator)
• iPhone (wireless) (mobile) • • ios • iOS 26.6.1 23G83
• iPhone 17 Pro Max (mobile) • • ios • iOS 26.5 (simulator)
• macOS (desktop) • macos • darwin-arm64 • macOS 26.6.2 25G83 darwin-arm64
• Chrome (web) • chrome • web-javascript • Google Chrome 152.0.7977.65
[✓] Network resources [162ms]
• All expected network resources are available.
! Doctor found issues in 1 category.
```
Contributor guide
Assessment
This issue has not been assessed yet.