MicrosoftEdge/WebView2Feedback

[Problem/Bug]: visibilitychange doesn't fire when parent window is minimized or covered

pushkin- opened this issue · 2 comments

What happened?

Reopening this issue: #2681

The visibilitychange event doesn't fire when the window hosting a webview2 control is minimized or covered by another window. This works correctly in Electron, because they handle it themselves

The closed issue said "currently, it's by design" and proposed a workaround (for just the minimize issue, not the other one).

I think it would be nice if they baked this workaround into WebView2, so the browser events fire as expected, by checking the hosting window.

Importance

Moderate. My app's user experience is affected, but still usable.

Runtime Channel

Stable release (WebView2 Runtime)

Runtime Version

129.0.2792.89

SDK Version

1.0.2535.41

Framework

Winforms

Operating System

Windows 11

OS Version

22631.4317

Repro steps

  1. launch minimal app
  2. open devtools and execute document.addEventListener("visibilitychange", () => console.log(document.visibilityState), true)
  3. minimize the window or cover it fully by another window and notice that you don't get any logs

Repros in Edge Browser

No, issue does not reproduce in the corresponding Edge version

Regression

No, this never worked

Last working version (if regression)

No response

And handling the other case and detecting when a window is covered by another seems to require a timer that fires periodically and sets WebView::Visible to false when covered. This means that when you uncover the window, there will be a period of time when it's just black.

Making the timer fire way more frequently (and same for other windows) seems suboptimal.