Webview2: Window blur and focus event always firing when clicking a button
Closed this issue · 5 comments
When clicking a button the blur and focus event always seem to fire on the window.
Steps to reproduce the bug
- Create basic WinUI3.0 desktop app only embedding a Webview2 control
- Set the source of the control to https://stackblitz.com/edit/window-focus-test-amkv5c?file=src/app/app.component.ts
- In the right panel only click the button
- Notice numbers are going up for the focus and blur event on the window as well
Expected behavior
Number should only increase for button clicks.
Other numbers should only increase if the focus is moved outside or back to the window.
Screenshots
Screenshot from WinUI app after clicking the button twice. Notice the blur and focus event being triggered as well.
Screenshot from Edge browser after clicking the button twice. Notice the blur event not being triggered and the focus event triggered once when user clicks the button and at same time gives focus to the window.
Version Info
Packaged WinUI3.0 Desktop app, WindowsAppSDK 8.0
NuGet package version:
WinUI 3 - Windows App SDK 0.8: 0.8.0
Windows app type:
UWP | Win32 |
---|---|
Yes |
Windows version | Saw the problem? |
---|---|
Insider Build (xxxxx) | |
October 2020 Update (19042) | |
May 2020 Update (19041) | Yes |
November 2019 Update (18363) | |
May 2019 Update (18362) | |
October 2018 Update (17763) | |
April 2018 Update (17134) | |
Fall Creators Update (16299) | |
Creators Update (15063) |
Device form factor | Saw the problem? |
---|---|
Desktop | Yes |
Xbox | |
Surface Hub | |
IoT |
Additional context
This is imporant since now in our web app we listen to the blur event on the window to close some modal dialogs automatically when the focus moves to another window. This issue prevents the user of just clicking on the button because the dialog is already closed at the moment the button click event is being handled.
Also this works both in Edge and a Win32 C++ app (taken from here https://github.com/MicrosoftEdge/WebView2Samples/tree/master/SampleApps/WebView2APISample) so seems related to WinUI3.0. Hence I'm reporting it here instead of on the Webview2 feedback repo.
@koenvd This sounds like it might be a known issue where the WebView2 control thinks it loses focus when the Edge WebView2 inside it gets focus. It's something I'm actively working on -- clearly it has a lot of unfortunate side effects, like (probably) this one.
FYI but this also works on UWP with the backported Webview2 part of WinUI 2.7.0-prerelease.210827001.
FYI but still seems to fail with WindowsAppSdk v1.0.0-preview1.
Fixed in Windows App SDK 1.0.1, check out the release notes for more info.