Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inability to Detect Close Event When WebView is Terminated at the OS Level On Windows #2530

Open
momadvisor opened this issue Feb 13, 2025 · 0 comments · May be fixed by #2543
Open

Inability to Detect Close Event When WebView is Terminated at the OS Level On Windows #2530

momadvisor opened this issue Feb 13, 2025 · 0 comments · May be fixed by #2543
Labels
bug Something isn't working

Comments

@momadvisor
Copy link

momadvisor commented Feb 13, 2025

Background

I am developing a Windows application. Due to text rendering issues (not-clear text issues) on Windows with skia, I am implementing my chat room area by embedding InAppWebView. So my purpose of putting InAppWebView into my widget tree is to work around the text rendering problems.

How WebView is Used

The area wrapped by the Container with the red border in the image below is the InAppWebView widget.

Image

Actual Behavior (Problem)

If I press the Alt + F4 shortcut key while the WebView area is focused, the WebView terminates. When the WebView is terminated in this way, no event is triggered. I cannot detect that the WebView has been terminated.

Image

Expected Behavior

Both of the followings. Or either one.

  1. If I press the Alt + F4, the entire app should be terminated, not only the WebView.
  2. It should be possible to detect when the WebView is terminated.

Steps with code example to reproduce

  1. Windows environment desktop app
  2. Mouse click on the WebView area to focus the WebView area
  3. Press ALT + F4

Flutter version

v3.27.4

Operating System, Device-specific and/or Tool

flutter doctor

Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 3.27.4, on Microsoft Windows [Version 10.0.19045.3803])
[√] Windows Version (Installed version of Windows is version 10 or higher)
[√] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[√] Chrome - develop for the web
[√] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.13.0)
[√] Android Studio (version 2023.1)
[√] VS Code (version 1.97.1)
[√] Connected device (3 available)
[√] Network resources

Plugin version

v6.1.5

Troubleshooting Attempts

  1. (JavaScript) onbeforeunload

    This failed because the termination occurs first at the OS level before the JavaScript event can be triggered.

  2. (InAppWebView) onCloseWindow

    This does not work because the WebView is terminated before the WindowCloseRequest event is detected.

  3. (Flutter) Wrapping InAppWebView with KeyboardListener

    While the WebView is focused, no event that KeyboardListener can detect is triggered even if a key is pressed.

  4. (Flutter) Prevent Being Focused with IgnorePointer
    My chat system needs a clickable message(e.g. download). So there are restrictions to use it.

  5. Reasearch on Other Libraries

    1. desktop_webview_window

    This library can detect the close event. However, it cannot be embedded within the screen as a Flutter widget. It operates in a separate window. I believe it can detect the close event because it operates in a separate window.

    The key of this library's close event listener seems to be implementing MessageHandler in desktop_webview_window/windows/webview_window.cc. I believe the implementation above could be a big hint to solving the issue at hand.

    Since it appears in a separate window, it cannot be used as an alternative to InAppWebView.

    1. webview_win_floating

    This library does not implement texture. So always the WebView floating. Perhaps because of this, there is no special reaction in the WebView even if Alt + F4 is pressed. Naturally, the entire Flutter app is terminated after Alt + F4 is pressed.

    However, due to an absence of texture, there are too many restrictions to use it.

    1. the others

    the other libraries are in the same situation as flutter_inappwebview (either they cannot detect a close event with their own event listener such as onCloseWindow of InAppWebView or they don't have any event listeners related with termination).

@momadvisor momadvisor added the bug Something isn't working label Feb 13, 2025
@momadvisor momadvisor linked a pull request Feb 25, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant