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 a webview can use for rendering. This method is asynchronous in order to allow textures to be created on the render thread, and the provided callback is called once the material has been created.

Important note

WebViewPrefab and CanvasWebViewPrefab take care of material creation for you, so you only need to call this method directly if you need to create an IWebView instance outside of a prefab with Web.CreateWebView().

CreateTexture

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

Creates a special texture that a webview can use for rendering, using the given width and height in Unity units (not pixels). The webview plugin automatically resizes a texture when it initializes or resizes a webview, so in practice, you can simply use the dimensions of 1x1 like CreateTexture(1, 1, callback). This method is asynchronous in order to allow textures to be created on the render thread, and the provided callback is called once the material has been created.

Important note

WebViewPrefab and CanvasWebViewPrefab take care of texture creation for you, so you only need to call this method directly if you need to create an IWebView instance outside of a prefab with Web.CreateWebView().

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.

Currently, iOS is the only platform that always uses a separate texture for video. Android only uses a separate video texture on versions of Android older than 6.0. For other platforms, video content is always integrated into the main texture.

Important note

WebViewPrefab and CanvasWebViewPrefab take care of material creation for you, so you only need to call this method directly if you need to create an IWebView instance outside of a prefab with Web.CreateWebView().

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.

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