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.
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?
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
anybody else experiencing problems when the path to WebView2Loader.dll contains special characters? I have customers who use Korean characters in their windows username and the WindowsWebView2WebBrowserComponent does apparently not like that…
Thanks for the reply! tried to make that work but no success. not sure if the changes I made in the .vcxproj are applicable because in Projucer I set the “Runtime Library” option to “use Dll runtime” because I do need to add other libraries dynamically and I guess there is a conflict.
It doesn’t manage to start the WebView2 with these instructions but if you have any experience with the projucer and the instructions above it would be much appreciated!
FWIW I managed to avoid the whole DLL linking/redistribution nightmare in my choc webview2 wrapper. It’s a single-header include which requires no runtime components and nothing else to be done to your project to make it compile:
It uses some pretty ugly tricks behind the scenes, but has been out in the wild for a while now and seems to work fine.
I don’t know if the JUCE team decided not to use this for a particular reason, but CHOC has a permissive license, so could be used internally in JUCE to provide this functionality if anyone wanted to… Just sayin’