WebView2 in JUCE 8 – JS App Reloads After Window Minimize on Windows

Hello,

Based on the JUCE tutorial for version 8, I’ve prepared an application that uses the WebView2 component to display a simple React app (Hello World) with two buttons. The second button triggers a native function that returns a string and has a side effect: after approximately 5 seconds, it calls emitEventIfBrowserIsVisible and performs a direct JS code evaluation (with the same logic).

Everything works as expected unless I minimize the window. When minimized, nothing happens, and the WebView’s inspect tool shows that the site appears to have reloaded - but without full initialization. After restoring the window, the page refreshes again, and this time everything loads correctly. However, any events triggered before minimizing are lost because the JS listener was never initialized.

This issue only occurs if I minimize the window before the first event cycle. If I avoid minimizing or minimize and restore once at the start, the problem does not repeat. I can reproduce this only on Windows (tested on Windows 11), while WSL/Ubuntu 24.04 and Ubuntu 25.04 do not exhibit this behavior.

I suspect this might be a WebView2 issue. I’ve tried disabling various features via flags without success, and I haven’t found any mention of similar problems elsewhere.

Environment:

  • Windows 11

  • JUCE 8 (latest)

  • WebView2 version: 1.0.3650.58

Resources:

Video explanation:

  • At the start, both backend and JS frontend are initialized.

  • Around 0:03, I trigger the native function call. The response is immediate, and two events will be posted after ~5 seconds.

  • At 0:04, I minimize the window. The WebView reloads its content, and the console shows only backend initialization. The JS listener is missing, so no events are received (~0:08).

  • After restoring, the frontend library loads, but the missed events are already gone.

  • At 0:15, I trigger the native function again without minimizing. Two alerts appear after ~5 seconds (~0:20).

  • If I repeat the minimize/restore now, everything works (~0:30).

  • Minimizing and restoring once at the start also fixes the issue (not shown in the video).

Has anyone encountered this behavior or found a workaround? Any insights would be appreciated.