Repository: flutter
Issue: `RawGestureDetector` on web fails to cancel gesture when `launchUrl()` gets called before the gesture ends
Labels: framework,f: gestures,platform-web,has reproducible steps,P2,team-framework,triaged-framework,found in release: 3.16,found in release: 3.18

### Is there an existing issue for this?

- [X] I have searched the [existing issues](https://github.com/flutter/flutter/issues)
- [X] I have read the [guide to filing a bug](https://flutter.dev/docs/resources/bug-reports)

### Steps to reproduce

1. Launch the provided example app on web (i used chrome)
2. Make a long press gesture
3. Return back to the app after a new browser tab opened
4. Try to do another long press gesture

- The works occasionally when using `ALT+Tab` too but is easier to reproduce with the `url_launcher` package.
- This bug does not seem to happen on Android or Windows.

### Expected results

- The `onLongPressUp` or `onLongPressCancel` callback gets called
- After returning to the app the `RawGestureDetector` should be able to listen to gesture inputs again. 


### Actual results

- `onLongPressUp` or `onLongPressCancel` doesn't get called
- The `RawGestureDetector` widget stopps listening to click events

### Code sample

<details><summary>Code sample</summary>

```dart
import 'dart:async';

import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';

void main() => runApp(const MyApp());

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      home: Scaffold(
        body: RawGestureDetector(
          gestures: <Type, GestureRecognizerFactory>{
            LongPressGestureRecognizer: GestureRecognizerFactoryWithHandlers<
                LongPressGestureRecognizer>(
                  () => LongPressGestureRecognizer(),
                  (LongPressGestureRecognizer instance) {
                instance
                  ..onLongPressDown = (_) {
                    print('onLongPressDown');
                  }
                  ..onLongPressUp = () {
                    print('onLongPressUp');
                  }
                  ..onLongPress = () {
                    print('onLongPress');
                    unawaited(launchUrl(Uri.parse('https://example.com')));
                  }
                  ..onLongPressCancel = () {
                    print('onLongPressCancel');
                  };
              },
            ),
          },
          child: Container(
            width: double.infinity,
            height: double.infinity,
            color: Colors.blueGrey,
          ),
        ),
      ),
    );
  }
}

```

</details>


### Screenshots or Video

<details>
<summary>Screenshots / Video demonstration</summary>

Note that I'm using Windows PowerToys to highlight clicks.

https://github.com/flutter/flutter/assets/34318751/1017255a-33e3-40ad-a5cc-deeb632013d0

</details>


### Logs

<details><summary>Logs</summary>

```console
onLongPressDown
onLongPress
```

</details>


### Flutter Doctor output

<details><summary>Doctor output</summary>

```console
[√] Flutter (Channel stable, 3.16.3, on Microsoft Windows [Version 10.0.22621.2715], locale de-DE)
    • Flutter version 3.16.3 on channel stable at C:\dev\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision b0366e0a3f (3 days ago), 2023-12-05 19:46:39 -0800
    • Engine revision 54a7145303
    • Dart version 3.2.3
    • DevTools version 2.28.4

[√] Windows Version (Installed version of Windows is version 10 or higher)

[!] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at C:\Users\User\AppData\Local\Android\sdk
    X cmdline-tools component is missing
      Run `path/to/sdkmanager --install "cmdline-tools;latest"`
      See https://developer.android.com/studio/command-line for more details.
    X Android license status unknown.
      Run `flutter doctor --android-licenses` to accept the SDK licenses.
      See https://flutter.dev/docs/get-started/install/windows#android-setup for more details.

[√] Chrome - develop for the web
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[√] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.7.6)
    • Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Community
    • Visual Studio Community 2022 version 17.7.34221.43
    • Windows 10 SDK version 10.0.22621.0

[!] Android Studio (not installed)

[√] VS Code (version 1.85.0)
    • VS Code at C:\Users\User\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension can be installed from:
       https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter

[√] Connected device (3 available)
    • Windows (desktop) • windows • windows-x64    • Microsoft Windows [Version 10.0.22621.2715]
    • Chrome (web)      • chrome  • web-javascript • Google Chrome 119.0.6045.200
    • Edge (web)        • edge    • web-javascript • Microsoft Edge 119.0.2151.93

[√] Network resources
    • All expected network resources are available.

! Doctor found issues in 2 categories.
```

</details>