8

I have followed all the instructions from Getting Started with WebView2 (developer preview) to create an app that is using Microsoft Edge (Chromium). However, it is not able to find the Edge browser. I also tried the sample apps (this and this) but with the same results. I have built the apps both for 32- and 64-bit.

What I get from calling CreateWebView2EnvironmentWithDetails() is error 0x80070002, which is ERROR_FILE_NOT_FOUND (The system cannot find the file specified.)

HRESULT hr = CreateWebView2EnvironmentWithDetails(nullptr, nullptr, nullptr,
  Callback<IWebView2CreateWebView2EnvironmentCompletedHandler>(
     [hWnd](HRESULT result, IWebView2Environment* env) -> HRESULT {

        // Create a WebView, whose parent is the main window hWnd
        env->CreateWebView(hWnd, Callback<IWebView2CreateWebViewCompletedHandler>(
           [hWnd](HRESULT result, IWebView2WebView* webview) -> HRESULT {
              if (webview != nullptr) {
                 webviewWindow = webview;
              }

              // Resize WebView to fit the bounds of the parent window
              RECT bounds;
              GetClientRect(hWnd, &bounds);
              webviewWindow->put_Bounds(bounds);

              // Schedule an async task to navigate to Bing
              webviewWindow->Navigate(L"https://www.bing.com/");

              return S_OK;
           }).Get());
        return S_OK;
     }).Get());

if (!SUCCEEDED(hr))
{
  if (hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND))
  {
     MessageBox(
        nullptr,
        L"Couldn't find Edge installation. "
        "Do you have a version installed that's compatible with this "
        "WebView2 SDK version?",
        nullptr, MB_OK);
  }
  else
  {
     std::wstringstream formattedMessage;
     formattedMessage << L"Failed to create webview environment" 
                      << ": 0x" << std::hex << std::setw(8) << hr;
     MessageBox(nullptr, formattedMessage.str().c_str(), nullptr, MB_OK);
  }
}

I have:

  • Edge Version 79.0.309.60 (Official build) beta (64-bit)
  • Windows 10.0.17134
  • Visual Studio 2019 16.4.2

Any ideas why my Edge installation is not found?

Marius Bancila
  • 16,053
  • 9
  • 49
  • 91
  • 1
    Whether the WebView2 window display? Which version of WebView2 SDK are you using?I have tried [this sample](https://github.com/MicrosoftEdge/WebView2Samples#1-getting-started-guide/) and using the Microsoft.Windows.ImplementationLibrary v1.0.191107.2 version and Microsoft.Web.WebView2 v0.8.355, the code work well on my side, you could check it. Besides, you might try to set the browserExecutableFolder through [CreateWebView2EnvironmentWithDetails](https://learn.microsoft.com/en-us/microsoft-edge/hosting/webview2/reference/webview2.idl#createwebview2environmentwithdetails) – Zhi Lv Jan 13 '20 at 10:25
  • Yes, I checked that too with the same result. – Marius Bancila Jan 13 '20 at 11:14
  • I tried specifying `C:\Program Files (x86)\Microsoft\Edge Beta\Application` for the first argument, but with the same error. Then I used process monitor and noticed that it is trying to look for the file EBWebView\x64\EmbeddedBrowserWebView.dll, so that is actually located under `c:\Program Files (x86)\Microsoft\Edge Beta\Application\79.0.309.63`. When I specified that, then it worked. However, I don't think that is good enough. I don't what to specify the folder of the installation. If I do this with an app that is installed at a customer, I want it to automatically figure its install path. – Marius Bancila Jan 13 '20 at 11:36
  • 1
    Refer to [this article](https://docs.microsoft.com/en-us/microsoft-edge/hosting/webview2/reference/iwebview2webview),we can see that when using the CreateWebView2EnvironmentWithDetails method, if null or empty string for browserExecutableFolder to create WebView, the API will try to find a compatible version of Edge installed on the machine according to the channel preference trying to find first per user install and then per machine install. It will auto detect the Edge (chromium) browser, in my side, in install the Microsoft Edge using the Default setting and it will auto detect the browser. – Zhi Lv Jan 14 '20 at 08:33

4 Answers4

6

Probably the version of the Browser is not compatible with the latest version of the SDK, you may have to go back some versions for it to work, following the list:

https://learn.microsoft.com/en-us/microsoft-edge/hosting/webview2/releasenotes

Edit: As informed by one of the developers of WebView2, at the moment WebView2 is still in preview version so always the latest version of Webview2 will accompany the latest canary version of Edge.

https://github.com/MicrosoftEdge/WebViewFeedback/issues/103#issuecomment-575287157

Fernando Vellozo
  • 6,195
  • 2
  • 14
  • 12
6

I got the same error, and after installed WebView2 Runtime , it works. https://developer.microsoft.com/microsoft-edge/webview2

Jim
  • 61
  • 1
  • 2
5

You must install the WebView2 runtime in order to run the compatible applications.

Also, you need to upgrade the NuGet package, maybe in your code you still have the reference of "pre-release version". In that version, "WebView2Environment" was missing it was kind of "WebView2Experiment".

1
  • Update Edge to latest version.
  • Update Nuget WebView2 SDK to lastest (INCLUDE prelease)
Mark Yang
  • 226
  • 3
  • 16