WebView2Feedback icon indicating copy to clipboard operation
WebView2Feedback copied to clipboard

Keyboard and focus issues with WebView2 and WinForms on .NET preview 7

Open noseratio opened this issue 4 years ago • 7 comments

Description

I've tried the latest WebView2 (SDK v1.0.955-prerelease, runtime v92.0.902.84) with Windows Forms on .NET v6.0.100-preview.7. I'm seeing a lot of improvements, but I still could spot the following issues:

  • Alt+Space for system menu doesn't work when the focus is inside WebView2. OTOH, Alt+F4 does work as expected, I believe it didn't in early releases 👍.
  • App-specific WinForms accelerators (e.g., Alt+X) still don't work when the focus is inside WebView2. They do when the focus is inside a native control like TextBox. Related WPF issue: https://github.com/MicrosoftEdge/WebView2Feedback/issues/468.
  • Pressing and releasing Alt inside WebView2 activates WinForms menu, but the focus remains inside WebView2:

Version WebView2 SDK v1.0.955-prerelease WebView2 runtime v92.0.902.84 .NET v6.0.100-preview.7 Windows 10 v19043.1165

Repro Steps

  • Install .NET 6.0.100-preview.7 SDK: https://dotnet.microsoft.com/download/dotnet/thank-you/sdk-6.0.100-preview.7-windows-x64-installer
  • Clone the test repo: https://github.com/noseratio/WebView2WinFormsSysHotKeys .
  • Run: dotnet run

AB#34280866

noseratio avatar Sep 01 '21 10:09 noseratio

TBH, at this stage I feel like the best path for hosting WebView2 is to implement a custom wrapper on top of CoreWebView2 and CoreWebView2Controller.

That would give me direct access to important VW2 integration APIs like AcceleratorKeyPressed, GotFocus, LostFocus, MoveFocusRequested etc.

noseratio avatar Sep 03 '21 05:09 noseratio

Hey @noseratio - thanks for the bug reports! I believe these are mostly tracked in other issues, but I've added this to our scenario we have for tracking keyboarding issues and improving the experience here. We know this is currently a bad pain-point for devs using our .NET controls and have this as a high-priority scenario on our backlog. Thanks!

champnic avatar Sep 10 '21 00:09 champnic

Hi @champnic, thanks for putting it on track. FWIW, the current keyboard/focus behavior is a lot better than that of BlazorWebView, at least in its current iteration where it's practically unusable: https://github.com/dotnet/maui/issues/2341.

I keep saying it... I believe would be beneficial for both Microsoft and the WebView2 dev community if (at least) the .NET wrappers for WebView2 were made open-source.

Some folks, me included, have been dealing with browser control integration issues since the early days of IE ActiveX-based WebBrowser wrappers in .NET. We might help fixing a bug or adding a feature. For example, BlazorWebView again, like this kind of things.

noseratio avatar Sep 10 '21 02:09 noseratio

Hi, @noseratio! We have released a new feature in the recent release(109). Focus and Inputs will be on native apps in this mode. You can enable this mode by enabling the feature flag ("--enable-features=msWebView2BrowserHitTransparent") in CoreWebView2CreationProperties.AdditionalBrowserArguments or CoreWebView2EnvironmentOptions.AdditionalBrowserArguments. I think enabling this feature will make Alt+X work(still some work to make Alt+Space work). Because this is a big change, there may be new bugs in this new feature. Please notify us if you find new issue related to the new feature.

zhuhaichao518 avatar Jan 30 '23 02:01 zhuhaichao518

@zhuhaichao518 thank you - well done, good to see some progress! I'll give this new feature a try and will report what I'll find.

noseratio avatar Jan 30 '23 11:01 noseratio

What is the current state of this? It appears that there is still no official documentation about this feature. It isn't even listed in here.

IMFJS avatar Aug 12 '24 13:08 IMFJS

We now have a ControllerOptions API for enabling this, instead of the feature flag: https://learn.microsoft.com/en-us/dotnet/api/microsoft.web.webview2.core.corewebview2controlleroptions.allowhostinputprocessing?view=webview2-dotnet-1.0.2730-prerelease

champnic avatar Aug 13 '24 23:08 champnic

We now have a ControllerOptions API for enabling this, instead of the feature flag: https://learn.microsoft.com/en-us/dotnet/api/microsoft.web.webview2.core.corewebview2controlleroptions.allowhostinputprocessing?view=webview2-dotnet-1.0.2730-prerelease

@champnic AllowHostInputProcessing has been implemeted in 1.0.2415-Prerelease at 26th February 2024. All other changes in this version already have been released, except this very important Parameter. Who do I have to contact to get someone to take care of it after more than a year? It's unacceptable that such a fundamentally important point is only pre-release for 15 months.

DerValiser avatar May 16 '25 10:05 DerValiser