Web

static class

Namespace: Vuplex.WebView

The Web static class contains APIs that globally impact the behavior of all IWebView instances, such as configuration options and global actions. It also contains the CreateWebView() method for creating an IWebView directly.

Important note

The Web class's APIs cannot be used before Awake() is first called for the app. Attempting to use a Web API prior to Awake() will result in an InvalidOperationException.

Summary

Public properties

CookieManager

static ICookieManager? CookieManager { get; }

Returns the ICookieManager for managing HTTP cookies, or null if ICookieManager isn't supported on the current platform.

ICookieManager is supported by all of the 3D WebView packages except for:

DefaultPluginType

static void DefaultPluginType { get; }

Gets the default 3D WebView plugin type among those installed for the current platform.

Public methods

ClearAllData

static void ClearAllData()

Clears all data that persists between webview instances, like cookies, storage, and cached resources.

Example

void Awake() {
    Web.ClearAllData();
}

Important notes

  • On Windows and macOS, 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().

  • On Universal Windows Platform, this method is unable to clear cookies due to a UWP limitation.

CreateWebView

static IWebView CreateWebView()

Creates a new webview in a platform-agnostic way. After the IWebView is created, it must be initialized by calling Init() method.

Example

var webView = Web.CreateWebView();
// Initialize the webview to 600px x 300px.
await webView.Init(600, 300);
webView.LoadUrl("https://vuplex.com");
// Set the Material attached to this GameObject to display the webview.
GetComponent<Renderer>().material = webView.CreateMaterial();

Important note

WebViewPrefab and CanvasWebViewPrefab take care of creating and managing an IWebView instance for you, so you only need to call this method directly if you need to create a webview outside of a prefab (for example, to connect it to your own custom GameObject).

EnableRemoteDebugging

static void EnableRemoteDebugging()

Example

void Awake() {
    Web.EnableRemoteDebugging();
}

Important note

On Windows and macOS, 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().

SetAutoplayEnabled

static void SetAutoplayEnabled(bool enabled)

By default, browsers block sites from autoplaying video with audio, but this method can be used to enable autoplay.

Example

void Awake() {
    Web.SetAutoplayEnabled(true);
}

Important notes

  • On Windows and macOS, 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().

  • This method works for every package except for 3D WebView for UWP, because the underlying UWP WebView control doesn't allow autoplaying video with audio.

SetCameraAndMicrophoneEnabled

static void SetCameraAndMicrophoneEnabled(bool enabled)

By default, web pages cannot access the device's camera or microphone via JavaScript, but this method can be used to grant all web pages access to the camera and microphone. This is useful, for example, to enable WebRTC support. Note that on macOS, Android, iOS, and UWP, additional project configuration is needed in order to enable permission for the camera and microphone. Camera and microphone permissions are enabled together with a single method because on some platforms (Windows, macOS, UWP), these permissions can only be enabled together and cannot be enabled separately.

Example

void Awake() {
    Web.SetCameraAndMicrophoneEnabled(true);
}

Important notes

  • On Windows and macOS, 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().

  • On iOS, enabling the camera and microphone is only supported in iOS 14.3 or newer and is only supported in Native 2D Mode.

SetIgnoreCertificateErrors

static void SetIgnoreCertificateErrors(bool ignore)

By default, browsers block https URLs with invalid SSL certificates from being loaded. However, this method can be used to ignore certificate errors.

Example

void Awake() {
    Web.SetIgnoreCertificateErrors(true);
}

Important notes

SetStorageEnabled

static void SetStorageEnabled(bool enabled)

Controls whether data like cookies, localStorage, and cached resources is persisted between webview instances. The default is true, but this can be set to false to achieve an "incognito mode".

Example

void Awake() {
    Web.SetStorageEnabled(false);
}

Important notes

  • On Windows and macOS, 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().

  • On Universal Windows Platform, this method doesn't disable cookies due to a UWP limitation.

SetUserAgent

static void SetUserAgent(bool mobile)

Globally configures all webviews to use a mobile or desktop User-Agent. By default, webviews use the browser engine's default User-Agent, but you can force them to use a mobile User-Agent by calling Web.SetUserAgent(true) or a desktop User-Agent with Web.SetUserAgent(false).

Example

void Awake() {
    // Use a desktop User-Agent
    Web.SetUserAgent(false);
}

SetUserAgent

static void SetUserAgent(string userAgent)

Globally configures all webviews to use a custom User-Agent.

Example

void Awake() {
    // Use FireFox's User-Agent.
    Web.SetUserAgent("Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0) Gecko/20100101 Firefox/91.0");
}