3D WebView for Windows and macOS embeds the Chromium browser engine, and by default, it creates and uses a browser cache directory at a default, app-specific path listed here. This browser cache directory is where Chromium saves state that it persists between multiple runs, such as cookies, localStorage, and its HTTP cache. These default cache settings works well as long only one instance of the app is running at at time. However, if you need to allow multiple instances of your application to run at the same time, these default settings will not suffice. A limitation of Chromium is that only one instance at a time can use a given browser cache directory. If multiple instances of an app using the default Chromium cache directory path run at the same time, it causes Chromium to crash, which leads to error messages in Unity like this on Windows:
[3D WebView] [0925/124442.660:ERROR:ChromiumLogFunctions.h(15)] [WindowsChromiumToPluginBridge] WriteFile failed with error code: 6
[3D WebView] Pipe client disconnected.
[3D WebView] [WindowsPluginToChromiumBridge] WriteFile failed with error code: 232
The good news is that you can use the following steps to enable multiple instances of your app to run simultaneously:
First, make sure that your project is using 3D WebView v4.10.1 or newer. 3D WebView logs its version number in the editor like described here. Some older versions of 3D WebView (v4.8 - v4.10) have a bug that prevent multi-instance support from being enabled successfully, so it is necessary to use v4.10.1 or newer.
Next, add a C# script that calls StandaloneWebView.SetCachePath() to set a different, unique cache path for each application instance. For example:
void Awake() {
// TODO: Assign each app instance a unique ID for its cache path.
var appInstanceID = 1;
var instanceCachePath = Path.Combine(Application.persistentDataPath, $"chromium-cache-{appInstanceID}");
#if UNITY_STANDALONE || UNITY_EDITOR
StandaloneWebView.SetCachePath(instanceCachePath);
#endif
}
After you perform these two steps, multiple instances of your app will be able to run simultaneously. Note that in older versions of 3D WebView prior to v4.8, it was possible to enable multi-instance support by disabling storage with Web.SetStorageEnabled(false). Due to changes in newer versions of Chromium, that approach no longer works for enabling multi-instance support, so the approach described above of assigning a unique cache path for each instance is required.