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 events always fire when clicking the WebView #9288

Closed
atom-b opened this issue Jan 26, 2024 · 13 comments
Closed
Labels
area-WebView bug Something isn't working closed-Fixed Described behavior has been fixed. team-Controls Issue for the Controls team
Milestone

Comments

@atom-b
Copy link

atom-b commented Jan 26, 2024

Describe the bug

When the WebView2 already has focus, clicking anywhere inside the WebView2 will trigger a window blur event followed immediately by a window focus event. Repeated clicks inside the window will trigger a blur and focus event for each click.

Steps to reproduce the bug

The repro steps in #5615 work, and clicking anywhere within the white test area will reproduce the bug, not just the button.

The bug can also be reproduced on any page, including an empty HTML page:

  1. Create basic WinUI3.0 desktop app using WindowsAppSDK 1.4 or newer.
  2. Edit MainWindow.xaml to contain just a Webview2 control
  3. Set the control's Source to a valid URL such as https://www.microsoft.com. Alternatively, add MyWebView.NavigateToString(""); to your CoreWebView2Initialized event handler.
  4. Build and run the application.
  5. Open the WebView2 Chrome dev tools by right-clicking the WebView control and selecting "Inspect", or with the hotkey control-shift-i.
  6. In the dev tools script console, paste and run the following script to log window.blur and window.focus events:
    window.onblur = function() { console.log("window.onblur"); }; window.onfocus = function() { console.log("window.onfocus"); };
  7. Click once on the WebView to bring it into focus.
  8. Observe that the console has logged a focus, a blur, and a focus event.
  9. Repeatedly click anywhere in the WebView and observe that the console logs a blur and focus event for each click.

Expected behavior

Window blur and focus events are only fired when the window loses and regains focus, respectively, and only once per triggering event. Window blur and focus events are not fired when clicking inside the WebView that already has focus.

Screenshots

image

NuGet package version

WinUI 3 - Windows App SDK 1.4.4: 1.4.231219000

Windows version

Windows 10 (21H2): Build 19044

Additional context

This is very similar to issue #5615 but a button is not required. The bug will repro on an empty HTML page.

I've repro'd the bug in the first and last stable WindowsAppSDK 1.4 releases (1.4.230822000 and 1.4.231219000), as well as WindowsAppSDK 1.5.240124002-experimental2). This bug does not repro in WIndowsAppSDK 1.3.230724000.

@atom-b atom-b added the bug Something isn't working label Jan 26, 2024
@microsoft-github-policy-service microsoft-github-policy-service bot added the needs-triage Issue needs to be triaged by the area owners label Jan 26, 2024
Copy link

Hi I'm an AI powered bot that finds similar issues based off the issue title.

Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one. Thank you!

Open similar issues:

Closed similar issues:

Note: You can give me feedback by thumbs upping or thumbs downing this comment.

@atom-b
Copy link
Author

atom-b commented Jan 26, 2024

Hi I'm an AI powered bot that finds similar issues based off the issue title.

...
* Webview2: Window blur and focus event always firing when clicking a button (#5615), similarity score: 0.96

Issue #5615 is a very similar bug, and the bug I'm reporting may be a regression that reintroduced #5615, but I cannot confirm this.

@codendone codendone added area-WebView team-Controls Issue for the Controls team and removed needs-triage Issue needs to be triaged by the area owners labels Feb 15, 2024
@koenvd
Copy link

koenvd commented Feb 21, 2024

What version of WinAppSDK are you using @atom-b ? And does it still happen if you downgrade to older WinAppSDK version?

@koenvd
Copy link

koenvd commented Feb 21, 2024

Ah right. I do see your comment now about not happening in 1.3.

Is it somehow possible to get this looked at @codendone because don't think we can upgrade to 1.5 when this issue is not fixed (In our app we track how long a page has focus so the focus event is imported for us).

@codendone
Copy link
Contributor

There's a fix in progress for MicrosoftEdge/WebView2Feedback#4140 which appears to also be fixing this issue.

@koenvd
Copy link

koenvd commented Feb 26, 2024

Thanks!

So we cannot expect a fix before WindowsAppSDK 1.6? (based on comment in the linked ticket MicrosoftEdge/WebView2Feedback#4140 (comment)).

That would mean for us that we would be stuck on 1.3 for a while ...

@codendone
Copy link
Contributor

Servicing to 1.5 is still a possibility. I tagged the internal bug to ensure it is considered for servicing once the fix is in 1.6 and verified.

@llongley llongley added this to the WinAppSDK 1.6 milestone Mar 21, 2024
@llongley llongley added the closed-Fixed Described behavior has been fixed. label Mar 21, 2024
@BethMassi
Copy link
Member

@codendone Did this get approved for 1.5 servicing? We have MAUI users reporting this issue as well. Thanks!

@microsoft-github-policy-service microsoft-github-policy-service bot added the needs-triage Issue needs to be triaged by the area owners label May 30, 2024
@codendone
Copy link
Contributor

This fix will be in the next 1.5 servicing release.

@grabinat
Copy link

grabinat commented Jun 7, 2024

There's a fix in progress for MicrosoftEdge/WebView2Feedback#4140 which appears to also be fixing this issue.

@codendone
You mentioned that this fix should also be fixing the issue with the flyout in webview2. I tested this with WinAppSDK 1.6 experimental1. However, the issue still seems to persist in 1.6 experimental1 (MicrosoftEdge/WebView2Feedback#4140).
Following related issue also still repoproduces under 1.6 experimental:
#5615

Therefore, I just wanted to check, if those bugs get fixed separately? And if so, are there also on track for the 1.6 release?

@codendone
Copy link
Contributor

@grabinat Interesting. I believe you're talking about #9566. That was supposed to be fixed by the change for this issue. Please add your comment on that issue for us to re-evaluate that one. Thanks!

@grabinat
Copy link

grabinat commented Jun 7, 2024

@codendone Oh - I thought it was related to issue because of that comment from this thread: #9288 (comment)
But no worries, then I will post in the other thread as well.

@codendone codendone removed the needs-triage Issue needs to be triaged by the area owners label Jun 7, 2024
@codendone
Copy link
Contributor

The fix is now also in Version 1.5.4 (1.5.240607001).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-WebView bug Something isn't working closed-Fixed Described behavior has been fixed. team-Controls Issue for the Controls team
Projects
None yet
Development

No branches or pull requests

6 participants