StandaloneWebView is the IWebView implementation used by 3D WebView for Windows and macOS. It also includes additional APIs for Standalone-specific functionality.
Task<string> CreatePdf(StandalonePdfOptions pdfOptions)
Like IWithPdfCreation.CreatePdf(), but accepts an additional parameter with options for formatting the PDF.
#if UNITY_STANDALONE || UNITY_EDITOR
var standaloneWebView = webViewPrefab.WebView as StandaloneWebView;
var pdfFilePath = await standaloneWebView.CreatePdf(new StandalonePdfOptions {
PageRanges = "1-3",
PreferCssPageSize = true,
PrintBackground = true
});
// Now that the PDF has been created, do something with it.
// For example, you can move it to a different location.
File.Move(pdfFilePath, someOtherLocation);
#endif
static Task<bool> DeleteAllCookies()
Deletes all cookies for all URLs and returns a Task<bool>
indicating whether the deletion succeeded.
#if UNITY_STANDALONE || UNITY_EDITOR
var succeeded = await StandaloneWebView.DeleteAllCookies();
#endif
static void EnableRemoteDebugging(int portNumber)
Like Web.EnableRemoteDebugging(), but starts the DevTools session on the specified port instead of the default port 8080.
void Awake() {
StandaloneWebView.EnableRemoteDebugging(9000);
}
static void SetCachePath(string absoluteFilePath)
By default, Chromium's cache is saved at the file path Application.persistentDataPath/Vuplex.WebView/chromium-cache, but you can call this method to specify a custom file path for the cache instead. This is useful, for example, to allow multiple instances of your app to run on the same machine, because multiple instances of Chromium cannot simultaneously share the same cache.
void Awake() {
#if UNITY_STANDALONE || UNITY_EDITOR
var customCachePath = Path.Combine(Application.persistentDataPath, "your-chromium-cache");
StandaloneWebView.SetCachePath(customCachePath);
#endif
}
This method cannot be executed while the Chromium browser process is running. So, you will likely need to call it from Awake() to ensure that it's executed before Chromium is started. Alternatively, you can manually terminate Chromium prior to calling this method using StandaloneWebView.TerminateBrowserProcess().
static void SetChromiumLogLevel(ChromiumLogLevel level)
Sets the log level for the Chromium logs. The default is ChromiumLogLevel.Warning. For a description of where the Chromium logs are written to, see SetChromiumLogPath()
void Awake() {
#if UNITY_STANDALONE || UNITY_EDITOR
StandaloneWebView.SetChromiumLogLevel(ChromiumLogLevel.Disabled);
#endif
}
This method cannot be executed while the Chromium browser process is running. So, you will likely need to call it from Awake() to ensure that it's executed before Chromium is started. Alternatively, you can manually terminate Chromium prior to calling this method using StandaloneWebView.TerminateBrowserProcess().
See also: SetChromiumLogPath
static void SetChromiumLogPath(string absoluteFilePath)
Overrides the absolute file path to which the Chromium debug log is written. By default, Chromium's log file is written to the following locations:
{ProjectPath}\Assets\Vuplex\WebView\Standalone\Windows\Plugins\VuplexWebViewChromium\log-chromium.txt~
{AppPath}\{AppName}_Data\Plugins\{Architecture}\VuplexWebViewChromium\log-chromium.txt
~/Library/Logs/Vuplex/log-chromium.txt
void Awake() {
#if UNITY_STANDALONE || UNITY_EDITOR
var customLogPath = Path.Combine(Application.persistentDataPath, "your-chromium-log.txt");
StandaloneWebView.SetChromiumLogPath(customLogPath);
#endif
}
This method cannot be executed while the Chromium browser process is running. So, you will likely need to call it from Awake() to ensure that it's executed before Chromium is started. Alternatively, you can manually terminate Chromium prior to calling this method using StandaloneWebView.TerminateBrowserProcess().
See also: SetChromiumLogLevel
static void SetCommandLineArguments(string args)
Sets additional command line arguments to pass to Chromium. For reference, here's an unofficial list of Chromium command line arguments.
void Awake() {
#if UNITY_STANDALONE || UNITY_EDITOR
StandaloneWebView.SetCommandLineArguments("--ignore-certificate-errors --disable-web-security");
#endif
}
This method cannot be executed while the Chromium browser process is running. So, you will likely need to call it from Awake() to ensure that it's executed before Chromium is started. Alternatively, you can manually terminate Chromium prior to calling this method using StandaloneWebView.TerminateBrowserProcess().
void SetNativeFileDialogEnabled(bool enabled)
The native file picker for file input elements is enabled by default, but it can be disabled with this method.
await webViewPrefab.WaitUntilInitialized();
#if UNITY_STANDALONE || UNITY_EDITOR
var standaloneWebView = webViewPrefab.WebView as StandaloneWebView;
standaloneWebView.SetNativeFileDialogEnabled(false);
#endif
static void SetScreenSharingEnabled(bool enabled)
By default, web pages cannot share the device's screen
via JavaScript. Invoking SetScreenSharingEnabled(true)
allows
all web pages to share the screen.
The screen that is shared is the default screen, and there isn't currently support for sharing a different screen or a specific application window. This is a limitation of Chromium Embedded Framework (CEF), which 3D WebView uses to embed Chromium.
void Awake() {
#if UNITY_STANDALONE || UNITY_EDITOR
StandaloneWebView.SetScreenSharingEnabled(true);
#endif
}
This method cannot be executed while the Chromium browser process is running. So, you will likely need to call it from Awake() to ensure that it's executed before Chromium is started. Alternatively, you can manually terminate Chromium prior to calling this method using StandaloneWebView.TerminateBrowserProcess().
static void SetTargetFrameRate(uint targetFrameRate)
Sets the target web frame rate. The default is 60
, which is also the maximum value. Specifying a target frame rate of 0
disables the frame rate limit.
void Awake() {
#if UNITY_STANDALONE || UNITY_EDITOR
// Disable the frame rate limit.
StandaloneWebView.SetTargetFrameRate(0);
#endif
}
This method cannot be executed while the Chromium browser process is running. So, you will likely need to call it from Awake() to ensure that it's executed before Chromium is started. Alternatively, you can manually terminate Chromium prior to calling this method using StandaloneWebView.TerminateBrowserProcess().
void SetZoomLevel(float zoomLevel)
Sets the zoom level to the specified value. Specify 0.0
to reset the zoom level.
// Set the zoom level to 1.75 after the page finishes loading.
await webViewPrefab.WaitUntilInitialized();
webViewPrefab.WebView.LoadProgressChanged += (sender, eventArgs) => {
if (eventArgs.Type == ProgressChangeType.Finished) {
#if UNITY_STANDALONE || UNITY_EDITOR
var standaloneWebView = webViewPrefab.WebView as StandaloneWebView;
standaloneWebView.SetZoomLevel(1.75f);
#endif
}
};
static Task TerminateBrowserProcess()
Terminates the Chromium browser process.
When 3D WebView for Windows and macOS initializes the application's first webview, it starts Chromium in a separate process. That Chromium process runs until the application closes, at which point 3D WebView automatically calls this method to terminate the Chromium process. However, in some rare cases, you may want your application to call this method manually to terminate Chromium while the app is still running. For example, some 3D WebView APIs like Web.ClearAllData() cannot be called while Chromium is running, but your application can use this method to terminate Chromium so that it can call those APIs. Prior to calling this method, your application must destroy all of the application's existing webviews (e.g. using WebViewPrefab.Destroy()). After Chromium finishes terminating, you can restart Chromium by creating new webview instances. (e.g. using WebViewPrefab.Instantiate()).
async void ClearDataAtRuntime() {
#if UNITY_STANDALONE || UNITY_EDITOR
// 1. Destroy all the webviews in the application.
var webViewPrefabs = GameObject.FindObjectsOfType<BaseWebViewPrefab>();
foreach (var prefab in webViewPrefabs) {
prefab.Destroy();
}
// 2. Terminate Chromium.
await StandaloneWebView.TerminateBrowserProcess();
// 3. Call the API that can't be called while Chromium is running.
Web.ClearAllData();
// 4. TODO: Create new webviews with WebViewPrefab.Instantiate() if needed.
#else
// On other platforms, Web.ClearAllData() can be called while the browser process is running.
Web.ClearAllData();
#endif
}