Skip to main content

Unity SDK Custom Windows WebView

The Immutable SDK for Unity helps you integrate your game with Immutable Passport.


Our Unity SDK does not support IL2CPP on Windows out of the box due to the lack of free, open-source Windows WebView solutions compatible with IL2CPP. However, it can be integrated with any custom Windows WebView that implements our specified interface.

In this guide, we will demonstrate how to use the Vuplex Windows WebView, a paid WebView that supports IL2CPP, to integrate it with our Unity SDK in your game.

  1. Purchase Vuplex Windows WebView. You will need to create an account with Vuplex to purchase it and download your purchased Windows WebView .unitypackage from your dashboard.

  2. In Unity, go to Assets -> Import Package -> Custom Package... and select the Vuplex Unity WebView .unitypackage which you downloaded from your dashboard.

    Note: When importing, ensure you include the Core/ and Standalone directories. You can skip the Mac directory inside the Standalone directory, as it is not needed for the Windows WebView integration.

Unity SDK import Vuplex
  1. Implement our custom Windows WebView interface IWindowsWebBrowserClient.
💡Note

Vuplex restricts the use of their Windows WebView in the Windows Unity Editor when targeting platforms other than Windows. Therefore, you should wrap your implementation with the following compilation flags: #if UNITY_STANDALONE_WIN || (UNITY_EDITOR_WIN && UNITY_STANDALONE_WIN).

This ensures that the code is only included when building for Windows standalone or when running in the Windows Unity Editor targeting Windows.

#if UNITY_STANDALONE_WIN

using System.IO;
using UnityEngine;
using Cysharp.Threading.Tasks;
using Immutable.Browser.Core;
using Vuplex.WebView;

public class VuplexWebView : IWindowsWebBrowserClient
{
public event OnUnityPostMessageDelegate OnUnityPostMessage;
private IWebView webView;

public VuplexWebView()
{
webView = Web.CreateWebView();
}

public async UniTask Init()
{
await webView.Init(1, 1);

// Listen to messages from WebView
webView.MessageEmitted += (sender, eventArgs) =>
{
OnUnityPostMessage?.Invoke(eventArgs.Value);
};
}

public void LoadUrl(string url)
{
webView.LoadUrl(url);
}

public async void ExecuteJavaScript(string js)
{
await webView.ExecuteJavaScript(js);
}

public string GetPostMessageApiCall()
{
return "window.vuplex.postMessage";
}

public void Dispose()
{
webView.Dispose();
}
}

#endif
  1. When initialising Passport, pass your custom Windows WebView to the Init function:
Passport passport = await Passport.Init(clientId, environment
// Only use Vuplex when building for Windows standalone or
// when running in the Windows Unity Editor targeting Windows
#if UNITY_STANDALONE_WIN || (UNITY_EDITOR_WIN && UNITY_STANDALONE_WIN)
, windowsWebBrowserClient: new VuplexWebView()
#endif
);
  1. In Unity, go to File -> Build Settings -> Player Settings... -> Player -> Settings for Windows, Mac, Linux -> Other Settings -> Under Scripting Define Symbols, click on the '+' button, add IMMUTABLE_CUSTOM_BROWSER and click Apply.

    This will ensure that the default Windows WebView used in our Unity SDK is not included in your game's build.

  2. If your game targets multiple platforms, ensure that Vuplex is excluded from builds for non-Windows platforms. For instructions on how to exclude Vuplex from your build, refer to Vuplex's guide here.