How to Force WebView2 Backend?

Hi,
I’m trying to use the chromium/edge backend in JUCE 8.0.6’s WebBrowserComponent, but it still defaults to the old Internet Explorer backend. Here’s what I’m doing:

WebBrowserDemo()
{
    setOpaque (true);

    WebBrowserComponent::Options::WinWebView2 winWebView2Options;
    winWebView2Options.withUserDataFolder(File::getSpecialLocation(File::userApplicationDataDirectory));
    WebBrowserComponent::Options options;
    options
        .withBackend(WebBrowserComponent::Options::Backend::webview2)
        .withWinWebView2Options(winWebView2Options);
    bool areSupported = WebBrowserComponent::areOptionsSupported(options); // returns true
    if(!areSupported)
    {
        jassertfalse;
    }

    webView = std::make_unique<WebBrowserComponent>(options);
    addAndMakeVisible(webView.get());


    webView->goToURL("https://www.whatismybrowser.com/");

    setSize (1000, 1000);
}

How can I force using webview2 backend?
Are there any known workarounds or additional settings to check?

Any help is appreciated!

Note that this does not modify options in-place. It creates a new options object with the specified settings:

    options
        .withBackend(WebBrowserComponent::Options::Backend::webview2)
        .withWinWebView2Options(winWebView2Options);

If you’re building with warnings enabled, the above code should alert you that the result of the method call is incorrectly being discarded.

You could try writing it like so instead:

const auto winWebView2 = WebBrowserComponent::Options::WinWebView2{}
    .withUserDataFolder (File::getSpecialLocation(File::userApplicationDataDirectory));

const auto options = WebBrowserComponent::Options{}
    .withBackend (WebBrowserComponent::Options::Backend::webview2)
    .withWinWebView2Options (winWebView2);

jassert (WebBrowserComponent::areOptionsSupported (options));

webView = std::make_unique<WebBrowserComponent> (options);
1 Like

Thank you for your help! It’s working now.