Web

static class

Web is the top-level static class for the module. It contains static methods for configuring the module and creating resources.

Summary

Public methods

ClearAllData

static void ClearAllData()

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

Note that on Windows and macOS, this method can only be called prior to creating any webviews.

CreateMaterial

static void CreateMaterial(Action<Material> callback)

Creates a material and texture that the webview can use for rendering.

Note that the WebViewPrefab takes care of material creation for you, so you only need to call this method directly if you create IWebView instances outside of a prefab using Web.CreateWebView().

Material creation occurs asynchronously in order to allow textures to be created on the render thread, and the provided callback is called once the material has been created.

CreateTexture

static void CreateTexture(float width, float height, Action<Texture2D> callback)

Creates a special texture that the webview can use for rendering.

Note that the WebViewPrefab takes care of texture creation for you, so you only need to call this method directly if you create IWebView instances outside of a prefab using Web.CreateWebView().

Texture creation occurs asynchronously in order to allow textures to be created on the render thread, and the provided callback is called once the texture has been created.

CreateVideoMaterial

static void CreateVideoMaterial(Action<Material> callback)

Like CreateMaterial, except it creates a material that a webview can use for rendering video. If the platform doesn't need a separate material and texture for video, this method returns null.

Android and iOS use a separate material and texture for video rendering, whereas standalone Windows and macOS do not.

CreateWebView

static IWebView CreateWebView()

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

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

Example:

Web.CreateMaterial(material => {
    // Set the material attached to this GameObject so that it can display the web content.
    GetComponent<Renderer>().material = material;
    var webView = Web.CreateWebView();
    webView.Init(material.mainTexture, 1, 1);
    webView.LoadUrl("https://vuplex.com");
});

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".

Note that on Windows and macOS, this method can only be called prior to creating any webviews.

SetUserAgent

static void SetUserAgent(bool mobile)

By default, webviews use a User-Agent that looks that of a desktop computer so that servers return the desktop versions of websites. If you instead want the mobile versions of websites, you can invoke this method with true to use the User-Agent for a mobile device.

Note that on Windows and macOS can only be called prior to creating any webviews.

SetUserAgent

static void SetUserAgent(string userAgent)

Configures the module to use a custom User-Agent string.

Note that on Windows and macOS can only be called prior to creating any webviews.