How to enable a network proxy?

The following sections describe how to enable a network proxy for different 3D WebView packages:

Enabling a network proxy for Windows and macOS

3D WebView for Windows and macOS embeds Chromium, and you can pass proxy credentials to Chromium using the --proxy-server command line argument described here. Here's an example of passing the --proxy-server argument to Chromium using StandaloneWebView.SetCommandLineArguments():

void Awake() {
    #if UNITY_STANDALONE || UNITY_EDITOR
        StandaloneWebView.SetCommandLineArguments($"--proxy-server={yourProxyServerUrl}");
    #endif
}

If a proxy server requires authentication with a username and password, your app can handle that using the IWithAuth interface.

Enabling a network proxy for Android

3D WebView for Android is powered by the Android System WebView, which doesn't have a built-in API for configuring a network proxy. However, there is an external androidx.webkit library that contains a ProxyController class that can be used to configure a proxy. I have a feature request to include the external androidx.webkit library as a dependency of 3D WebView, and I will update this article if I do that in the future. In the meantime, if you need to configure a network proxy for 3D WebView for Android, you can add the external androidx.webkit library to your Unity project and use Unity's AndroidJavaClass API to utilize its ProxyController class.

Enabling a network proxy for Android Gecko

For 3D WebView for Android with Gecko Engine, you can configure a proxy by using AndroidGeckoWebView.SetPreferences() to set proxy-related Gecko preferences. Here's an example of configuring an HTTP and HTTPS proxy:

void Awake() {
    #if UNITY_ANDROID && !UNITY_EDITOR
        var httpProxyHost = "5.79.68.1";
        var httpProxyPort = "12010";
        AndroidGeckoWebView.SetPreferences(new Dictionary<string, string> {
            ["network.proxy.type"] = "1",
            ["network.proxy.http"] = httpProxyHost,
            ["network.proxy.http_port"] = httpProxyPort,
            ["network.proxy.ssl"] = httpProxyHost,
            ["network.proxy.ssl_port"] = httpProxyPort
        });
    #endif
}

And here's an example of configuring a SOCKS proxy:

void Awake() {
    #if UNITY_ANDROID && !UNITY_EDITOR
        AndroidGeckoWebView.SetPreferences(new Dictionary<string, string> {
            ["network.proxy.type"] = "1",
            ["network.proxy.socks"] = "5.79.68.2",
            ["network.proxy.socks_port"] = "9050",
            ["network.proxy.socks_version"] = "5"
        });
    #endif
}

If a proxy server requires authentication with a username and password, your app can handle that using the IWithAuth interface.

Enabling a network proxy for UWP / Hololens

For 3D WebView for UWP / Hololens, you can configure a proxy server by setting the following capabilities in UWP Player Settings -> Publishing Settings:

  • EnterpriseAuthentication
  • PrivateNetworkClientServer
  • SharedUserCertificates

Please note that if you make changes to the project's UWP Publishing Settings, you must delete the project's existing UWP build folder in order to make Unity regenerate a new UWP app manifest.