MicrosoftEdge / MicrosoftEdge/WebView2Feedback
[Problem]: WebView2 won't work outside of a UI thread
@Lakshmisha-KS is already working on this.
Since Feb 12, 2025.
- Dominant language
- PowerShell
- Stars
- 526
- Forks
- 67
- PR merge metrics
- No merged PRs in 30d
Description
What happened?
Several issues come to the same conclusions:
The WV2's API need to run in a UI thread [from #3617]
there was no UI thread in my application, causing the await to hang [from #202 ]
This causes a hard dependency on heavy Windows DLLs to use a Dispatcher, and forces the host app to run as STA (Single-Threaded Apartment), de facto excluding async main for console apps (see this closed issue).
It would be beneficial to make this dependency more explicit and less cumbersome, eg:
- expose a way to create a
CoreWebView2without any reference to a UI framework and without creating an unusedCompositionController - remove dependency to a
IntPtr hwndwhen creating the webview - expose a way to initialize a
CoreWebView2by passing in aDispatcher, to make the dependency more explicit - remove WPF/Winforms from the NuGet package for purely headless uses
- document the issue more clearly and document the headless mode more clearly
Importance
Moderate. My app's user experience is affected, but still usable.
Runtime Channel
Stable release (WebView2 Runtime)
Runtime Version
No response
SDK Version
No response
Framework
Other
Operating System
Windows 11
OS Version
No response
Repro steps
in a blank console app Program.cs:
var env = await CoreWebView2Environment.CreateAsync();
var controller = await env.CreateCoreWebView2ControllerAsync(new IntPtr(-3)); // doesn't complete
var coreWebView = controller.CoreWebView2; // never reached
Repros in Edge Browser
Not Applicable
Regression
No, this never worked
Last working version (if regression)
No response
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.