When logon as an admin user, WebView2 raised Element not found COMException during the initialization #3997
Replies: 35 comments
-
Hello @DreamlandForsure , Thanks for your inquiry! I've assigned this to a dev that might best answer your question. |
Beta Was this translation helpful? Give feedback.
-
@LiangTheDev you've looked into this issue previously. Do you know if there is any solution or workaround? |
Beta Was this translation helpful? Give feedback.
-
The workaround for the normal case is to restart Windows Explorer using Task Manager. |
Beta Was this translation helpful? Give feedback.
-
Hi @victorthoang @david-risney , thanks for your prompt response and bridging the issue. |
Beta Was this translation helpful? Give feedback.
-
Sorry for the confusion, I am expecting the app not WebView2 Runtime to make a change to work around the situation so that we have an improved end user experience. |
Beta Was this translation helpful? Give feedback.
-
Hi @LiangTheDev , thanks for your kindly input. Let me discuss with our colleagues about if this is possible and how to implement the suggestion you proposed. |
Beta Was this translation helpful? Give feedback.
-
Hi! @LiangTheDev But I don't know how to solve the underlying problem. (Does the UI mean the UI of the entire app? Or is it limited to webview?) private async void Form1_Load(object sender, EventArgs e) {
webView_main = new WebView2() {
Visible = true,
Dock = DockStyle.Fill,
Source = new Uri("https://www.naver.com")
};
await webView_main.EnsureCoreWebView2Async(null);
} |
Beta Was this translation helpful? Give feedback.
-
@byungmeo @LiangTheDev In fact, this is the most troublesome problem for us. Several IPs report this error every day, and we did not expect so many at the beginning. The problem they mentioned should be because Windows has just logged in, so it needs to be delayed for a while to initialize, and most of the problems we encountered are concentrated in Win10 19044/19045, and the reason should be that the resource manager is not in a good state. |
Beta Was this translation helpful? Give feedback.
-
@byungmeo besides exception that would throw for await EnsureCoreWebView2Async, you could also use WebView2.CoreWebView2InitializationCompleted Event to get notified about the WebView creation result. |
Beta Was this translation helpful? Give feedback.
-
Is there any updates on this? I am facing similar problem where web view fails to start due to explorer state or in case its not running at all, agree @sln162 that there should be an option not to rely on explorer at will. |
Beta Was this translation helpful? Give feedback.
-
@olegsavelos |
Beta Was this translation helpful? Give feedback.
-
We made some changes in Edge 112 to rely less on explorer state, that's probably why switching to beta improved. But we still depend on explorer being there for launching non elevated Edge WebView2 process. |
Beta Was this translation helpful? Give feedback.
-
In my case the process is fully elevated, the only problematic scenario is when explorer have not been started yet. So how do I test beta ? Just install Edge beta version ? |
Beta Was this translation helpful? Give feedback.
-
I don't think running Edge beta would help as Edge 112 is already the current stable version. If explorer process is killed, I don't expect it to work. If you really want to try, you can install Edge beta and set environment variable WEBVIEW2_RELEASE_CHANNEL_PREFERENCE with value of 1 and then run the app. |
Beta Was this translation helpful? Give feedback.
-
@LiangTheDev Last time I noticed your mention of the changes in version 112 on another issue, and from our backend data, we did see a significant reduction in the "element not found" error, but it has not completely disappeared. The issue still exists in version 112.0.1722.64, but at least we appreciate your attention and efforts. Will future versions of 112 or version 113 continue to optimize this issue? Additionally, was this change made from the first version of 112? Or from which subversion did it start? Were there any changes related to this issue in the intermediate subversions? Because I want to limit the minimum runtime version and need a minimum version value, such as 112.0.1722.34. |
Beta Was this translation helpful? Give feedback.
-
@olegsavelos , the suggestion from BlazorWebView experts for how to retry: |
Beta Was this translation helpful? Give feedback.
-
I'm encountering a comparable problem with my implementation of WebView2 in a WPF app, using version 1.0.1722.45 of WebView2 and version 1.3.173.55 of the runtime. Specifically, when the app is running in admin mode, I'm receiving an "Element not found" error, but it works fine in normal user mode. Could you please provide some guidance on how to resolve this issue? Despite trying various approaches, I have been unable to find a solution. |
Beta Was this translation helpful? Give feedback.
-
@sachinverma0005 are you running in an environment where explorer is not running? It is currently a limitation of WebView2 and there is no workaround. |
Beta Was this translation helpful? Give feedback.
-
Yes, Explorer is not running. |
Beta Was this translation helpful? Give feedback.
-
That's expected behavior. WebView2 processes can't run elevated and we depend on explorer being there for launching non elevated Edge WebView2 process. For apps running as standard user, we can simply use CreateProcess to create WebView2 processe, and therefore no dependency on explorer. |
Beta Was this translation helpful? Give feedback.
-
So I suppose the non-elevated launch is not a requirement but instead an security measure ? I really wish there was an option to allow web view process run elevated when security is not an issue. |
Beta Was this translation helpful? Give feedback.
-
#1981 |
Beta Was this translation helpful? Give feedback.
-
@sln162 #2772 is not the same as this issue. That was about using async APIs of host object injected into scripts. Closed #1981, as that is the same as this one. |
Beta Was this translation helpful? Give feedback.
-
Is there source code for this behavior available ? I would like to check the exact conditions when the browser process is launched under explorer. The idea is that perhaps it would be possible to create limited token when initializing web view and cause it not to require the explorer , perhaps this is something that development team should consider? |
Beta Was this translation helpful? Give feedback.
-
The code is basically what's in https://devblogs.microsoft.com/oldnewthing/20131118-00/?p=2643. We also try to use methods described in https://stackoverflow.com/questions/11169431. |
Beta Was this translation helpful? Give feedback.
-
I see but what are conditions that determines if you should launch under explorer or not, I have tried impersonating the thread in multiple ways but still initialization of web view always fails with "Element not found" if explorer not running. Of course under the normal user that does not happen, so it would be nice to if you could clarify the conditions for launching under explorer as it would help me understand if impersonation route is possible or not. |
Beta Was this translation helpful? Give feedback.
-
You could try to create Edge/chrome browser process with --do-not-de-elevate --user-data-dir= to see whether that works. If that works, we should be able to also use the method to launch WebView2 processes. |
Beta Was this translation helpful? Give feedback.
-
I tried it but no luck.
Still if explorer not running "element not found", observing the user under which web view process runs reveals that its the current user and not the one being impersonated so I would assume you are not picking up the user from current thread ? |
Beta Was this translation helpful? Give feedback.
-
I see what you are asking. We are not picking up the impersonated token on the thread. WebView makes usage of multiple threads and lives longer than the impersonated period during webview2 initialization. And I am not sure whether parenting hwnds belongs to processes running as different users works or not. |
Beta Was this translation helpful? Give feedback.
-
I have created a seperate app, and opening that from my app (which is running in admin mode) with help of explorer.exe and that worked for me. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi, WebView2 team,
Our application integrated the webview2 runtime for an internal embedded browser. Now end users reported an issue that the embedded browser is not working well. After debugging we found that the exception is actually raised at calling EnsureCoreWebView2Async() internally. We just follow the webview2 example to initialize the webview2 control.
27/14:41:06 browsers T100 :The exception raised as System.Runtime.InteropServices.COMException (0x80070490): Element not found. (Exception from HRESULT: 0x80070490)
27/14:41:06 browsers T100 : at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)
27/14:41:06 browsers T100 : at Microsoft.Web.WebView2.Core.CoreWebView2Environment.d__45.MoveNext()
27/14:41:06 browsers T100 :--- End of stack trace from previous location where exception was thrown ---
27/14:41:06 browsers T100 : at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
27/14:41:06 browsers T100 : at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
27/14:41:06 browsers T100 : at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
27/14:41:06 browsers T100 : at Microsoft.Web.WebView2.Wpf.WebView2.<>c__DisplayClass27_0.<g__Init|0>d.MoveNext().
The repro steps are as following -
Expected behavior: the application would pop up a window to display a initial web page.
Actual behavior: the application pops up an error window which cannot display anything.
For the above scenario, there is no issue when use a non-admin user. And I also found there are below history tickets reported the similar issues. I confirmed that our application process is not the parent of the msedgewebview2.exe. My question is there any workaround to fix the issue? Or is there any fix developed for webview2 to fix the issue? Thanks.
#1981
#2780
"We often found this error when running the application as admin and explorer is not in a good state… You could verify whether WebView thinks that the application is running elevated, and it has to make usage of explorer to launch its processes by observing in Task Manager whether the Edge WebView2 processes (msedgewebview2.exe) are shown as child processes to the application process. If the WebView2 processes are not shown as child processes of the application process, it indicates that WebView2 thinks that the application is running elevated."
Beta Was this translation helpful? Give feedback.
All reactions