MicrosoftEdge / MicrosoftEdge/WebView2Feedback

[Problem/Bug]: System.InvalidCastException occurs when setting AllowHostInputProcessing to 'true'

Open
#5,394 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
PowerShell
Stars
526
Forks
67
PR merge metrics
No merged PRs in 30d

Description

What happened?

I have a UWP Xbox App with a WebView2 container that points to a web URL. I've mapped the gamepad keys to manually send the KeyboardEvents into the WebView2 so I'd like to set AllowHostInputProcessing to true so the same events don't get invoked within the webview. However, when I set the AllowHostInputProcessing to true in CoreWebView2ControllerOptions, it throws 'System.InvalidCastException'. I have the latest version of WebView2 v1.0.3537.50.

Image Image Image
Importance

Blocking. My app's basic functions are not working due to this issue.

Runtime Channel

Stable release (WebView2 Runtime)

Runtime Version

No response

SDK Version

No response

Framework

WinUI2/UWP

Operating System

Windows 11

OS Version

No response

Repro steps

This code block will cause the error to occur.
`
var webView2Environment = await CoreWebView2Environment.CreateWithOptionsAsync(string.Empty, string.Empty, new CoreWebView2EnvironmentOptions()
{
AreBrowserExtensionsEnabled = true,
});
var opts = webView2Environment.CreateCoreWebView2ControllerOptions();
opts.AllowHostInputProcessing = true;

`

Repros in Edge Browser

No, issue does not reproduce in the corresponding Edge version

Regression

No, this never worked

Last working version (if regression)

No response

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the provided UWP repro using CreateWithOptionsAsync, CreateCoreWebView2ControllerOptions, and the AllowHostInputProcessing assignment. Investigate the InvalidCastException against the stated WebView2 SDK version and determine whether the property can be set without the exception; no source files or tests are named.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
api, desktop
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.