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

Webview2: Window blur and focus event always firing when clicking a button #5615

Closed
koenvd opened this issue Aug 3, 2021 · 5 comments
Closed
Labels
area-WebView product-winui3 WinUI 3 issues team-Rendering Issue for the Rendering team

Comments

@koenvd
Copy link

koenvd commented Aug 3, 2021

When clicking a button the blur and focus event always seem to fire on the window.

Steps to reproduce the bug

  1. Create basic WinUI3.0 desktop app only embedding a Webview2 control
  2. Set the source of the control to https://stackblitz.com/edit/window-focus-test-amkv5c?file=src/app/app.component.ts
  3. In the right panel only click the button
  4. 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 2021-08-03 164103

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.

Screenshot 2021-08-03 164407

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.

@ghost ghost added the needs-triage Issue needs to be triaged by the area owners label Aug 3, 2021
@krschau
Copy link
Contributor

krschau commented Aug 3, 2021

@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.

@krschau krschau removed the needs-triage Issue needs to be triaged by the area owners label Aug 3, 2021
@codendone codendone added the team-Rendering Issue for the Rendering team label Aug 4, 2021
@koenvd
Copy link
Author

koenvd commented Aug 4, 2021

Thanks for the update and already working on this @krschau!

I think now #5570 is also probably one of the unfortunate side effects.

Leaving it up to you if you want to keep both issues open.

@koenvd
Copy link
Author

koenvd commented Sep 8, 2021

FYI but this also works on UWP with the backported Webview2 part of WinUI 2.7.0-prerelease.210827001.

@koenvd
Copy link
Author

koenvd commented Sep 23, 2021

FYI but still seems to fail with WindowsAppSdk v1.0.0-preview1.

@krschau krschau added the fixed-internally This bug has been fixed, and the fix will be shipped in the next version of WinUI 3. label Feb 1, 2022
@gabbybilka gabbybilka added this to the WinUI 3 in WinAppSDK 1.1 milestone Mar 14, 2022
@gabbybilka
Copy link
Member

Fixed in Windows App SDK 1.0.1, check out the release notes for more info.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-WebView product-winui3 WinUI 3 issues team-Rendering Issue for the Rendering team
Projects
None yet
Development

No branches or pull requests

5 participants