Webview2: Window blur and focus events always fire when clicking the WebView
atom-b opened this issue · 13 comments
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:
- Create basic WinUI3.0 desktop app using WindowsAppSDK 1.4 or newer.
- Edit MainWindow.xaml to contain just a Webview2 control
- Set the control's
Source
to a valid URL such as https://www.microsoft.com. Alternatively, addMyWebView.NavigateToString("");
to yourCoreWebView2Initialized
event handler. - Build and run the application.
- Open the WebView2 Chrome dev tools by right-clicking the WebView control and selecting "Inspect", or with the hotkey
control-shift-i
. - In the dev tools script console, paste and run the following script to log
window.blur
andwindow.focus
events:
window.onblur = function() { console.log("window.onblur"); }; window.onfocus = function() { console.log("window.onfocus"); };
- Click once on the WebView to bring it into focus.
- Observe that the console has logged a focus, a blur, and a focus event.
- 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
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.
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:
- Interacting with WebView2 in AppWindow causes the main window to be focused/activated instead of the AppWindow (#8113), similarity score: 0.76
- After WebView2 changes the window, clicking WebView2 will not activate the new window but the main window (#7335), similarity score: 0.72
- WebView2 triggers KeyboardAccelerator twice when focused (#6231), similarity score: 0.72
Closed similar issues:
- Webview2: Window blur and focus event always firing when clicking a button (#5615), similarity score: 0.96
- Possible bug on webview2. (#5410), similarity score: 0.71
Note: You can give me feedback by thumbs upping or thumbs downing this comment.
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.