WebView2 setup

Is anyone able to offer simple instructions on getting started with WebView2 on Windows?

I created a clean Projucer project and enabled WebView2, but when I compile it in Visual Studio 2019, I get an error that “WebView2.h” could not be found. I installed the WebView package via NuGet manually (though my understanding from this forum was that it should install itself automatically?), and then I get a different error that the DLL could not be copied as part of the copy phase of the build.

I’m new to Windows development so could be missing something obvious. This is a fresh install of Visual Studio Community 2019 on Windows 10 x64, choosing the “C++” preset when install VS.

The steps should be as follows:

  • Create a new project in the Projucer
  • Enable the JUCE_USE_WIN_WEBVIEW2 flag in juce_gui_extra
  • Re-save the project and open in Visual Studio
  • Use the WindowsWebView2WebBrowserComponent wrapper in your code instead of WebBrowserComponent which will allow you to specify a location for the WebView2Loader.dll and user data folder

You’ll need to ensure that a canary build of Microsoft Edge (minimum version 82.0.488.0) is installed at runtime, or use the Evergreen installer:

The fact that your build is failing at compile-time to find the headers indicates that the NuGet package hasn’t been properly installed. You shouldn’t need to install it manually as JUCE expects a specific version and will add this to the VS solution when you save the Projucer project. Did you definitely do a re-save before trying to build?

1 Like

Hey Ed,

Thanks for the reply! As expected it was user error – I had set this flag manually in “Extra Preprocessor Definitions” rather than in juce_gui_extra. All good now after installing the Evergreen installer too :slight_smile:

Thanks!

WebBrowserComponent::WebBrowserComponent (bool unloadWhenHidden)
    : browser (new Pimpl (*this, {}, {}, true/*false*/)),

on JUCE 6.0.5 Release, I manually edited this 4th argument from ”false" to “true”. I don’t know what’s up to date.

As mentioned above, you’ll need to use the WindowsWebView2WebBrowserComponent wrapper instead of WebBrowserComponent to use WebView2.

you’ll need to use the WindowsWebView2WebBrowserComponent wrapper instead of WebBrowserComponent to use WebView2.

Oh thank you.