-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WebView2 headless doesn't work in non-interactive login #4259
Comments
I don't believe this is intended to be supported previously. @champnic or @bradp0721 should know better. |
I believe this is currently By Design and has to do with trying to run as a non-logged-in user, rather than an issue with being headless or the HWND. Please see https://learn.microsoft.com/en-us/microsoft-edge/webview2/concepts/security: @cnevill-ge in your example does it end up trying to run the app as SYSTEM user? |
We weren't trying to run it as SYSTEM, but it was running as an elevated user in a non-interactive window station. From the debugger view in Visual Studio it sure looked like an async task was stuck waiting to run and never getting scheduled, but I'm not very strong on debugging that stuff. |
I Have Exactly Same Problem |
For now we "solved" it by switching to CefSharp. :/ Not the solution we hoped for, but we couldn't find any other workaround. |
I got this to work at some point with: private IntPtr HWND_MESSAGE = new IntPtr(-3);
protected async void InitializeAsync()
{
StringUtils.LogString("About to create WebView Controller " + HtmlToPdfHost.WebViewEnvironmentPath);
// must create a data folder if running out of a secured folder that can't write like Program Files
var environment = await CoreWebView2Environment.CreateAsync(userDataFolder: HtmlToPdfHost.WebViewEnvironmentPath);
// Worked a few releases back - now it's hanging here and never gets past this in unattended context
var controller = await environment.CreateCoreWebView2ControllerAsync(HWND_MESSAGE);
controller.DefaultBackgroundColor = ColorTranslator.FromHtml(HtmlToPdfHost.BackgroundHtmlColor ?? "white");
} Just to show that this was working with SYSTEM and ApplicationPoolIdentity in IIS a few months back. But... it looks like this behavior has a regression to no longer working in more recent builds and it now once again hangs on Point of this is that this was possible to do but something that's changed in the WebView code recently has broken to make this no longer work. FWIW, my use case is running this from IIS in an ASP.NET Core application. In that scenario it hangs now - again. I've tried using different user accounts SYSTEM, NETWORK Service, separate ADMIN user accounts (that do have a profile and profile enabled), but it always hangs. As said it was working at some point as shown in the screen cap - so what changed? Unfortunately I don't know what version of the SDK worked at the time - I've rolled back a through versions and I can't find any SDK version that works, but it could also be the Runtime that has the change? |
If anybody wants to mess around with this the above code comes from my Westwind.WebView repo, which includes HtmlToPdf functionality. It works fine interactively but problems non-interactive even though the code aims at the non-interactive environment. Relevant code here: |
What happened?
As noted by @Screaminlean in issue 202 it seems that calling
CreateCoreWebView2ControllerAsync
withHWND_MESSAGE
works fine in an interactive login, but if you run it from a non-interactive login (such as a service or scheduled task) it does not work.In my use case, the goal is to have an unattended service render a page that users would typically see interactively in WebView2, export that page view to a PNG, and provide it as part of an automated export to the customer.
In the sample code from issue 202 this manifests as a hang, but really a
COMException
is being thrown fromCreateCoreWebView2ControllerAsync
after the internal WebView2 code encounters an error. I also tried creating a dummy Form object inside the UI thread and passing that form's handle toCreateCoreWebView2ControllerAsync
, but it fails with the same error.Errors reported in the debugger output in the failing scenario:
I'm not sure if this scenario is supported but I really hope it's possible!
Importance
Important. My app's user experience is significantly compromised.
Runtime Channel
Stable release (WebView2 Runtime)
Runtime Version
120.0.2210.77
SDK Version
1.0.2210.55
Framework
Other
Operating System
Windows 10, Windows Server
OS Version
Windows 10: 19045.3693; Server 2022: 20348.2159
Repro steps
Repros in Edge Browser
Not Applicable
Regression
No, this never worked
Last working version (if regression)
No response
The text was updated successfully, but these errors were encountered: