MicrosoftEdge / MicrosoftEdge/WebView2Feedback

[Problem]: WebView2 won't work outside of a UI thread

Open
#4,198 16 comments 6 reactions 2 assignees View on GitHub

@Lakshmisha-KS is already working on this.

Since Feb 12, 2025.

feature request tracked
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 CoreWebView2 without any reference to a UI framework and without creating an unused CompositionController
  • remove dependency to a IntPtr hwnd when creating the webview
  • expose a way to initialize a CoreWebView2 by passing in a Dispatcher, 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

AB#48454374

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.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.