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?

2 Likes

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.

Would the WebView2Loader.dll be called EmbeddedBrowserWebView.dll aswell? I am unable to find WebView2Loader.dll anywhere in the links or the downloads.

Found it here: building the getting started guide

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! :slight_smile:

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’ :slight_smile:

1 Like

Good to know - I looked at choc and farbot for the Direct2D renderer, but wasn’t sure it would be acceptable to use either.

Good to hear from you, Jules!

Matt

@jules do you have an example of use of choc own webview in a Juce app ?
I suppose you can do this using NSViewComponent or HWNDComponent ?

Thanks !

Yes, that’s the general idea, which is what I did in the cmajor juce plugin wrapper:

1 Like