WebGLWebView

class : IWebView

Namespace: Vuplex.WebView

Additional interfaces: ?

The IWebView implementation used by 2D WebView for WebGL. This class also includes extra methods for WebGL-specific functionality.

Summary

Public properties

Public properties

IFrameElementID

string IFrameElementID

Gets the unique id attribute of the webview's <iframe> element.

Example

await canvasWebViewPrefab.WaitUntilInitialized();
#if UNITY_WEBGL && !UNITY_EDITOR
    var webGLWebView = canvasWebViewPrefab.WebView as WebGLWebView;
    Debug.Log("IFrame ID: " + webGLWebView.IFrameElementID);
#endif

Public methods

CanAccessIFrameContent

bool CanAccessIFrameContent()

Indicates whether 2D WebView can access the content in the webview's iframe. If the iframe's content can't be accessed, then most of the IWebView APIs become disabled. For more information, please see this article.

Example

await canvasWebViewPrefab.WaitUntilInitialized();
#if UNITY_WEBGL && !UNITY_EDITOR
    var webGLWebView = canvasWebViewPrefab.WebView as WebGLWebView;
    if (webGLWebView.CanAccessIFrameContent()) {
        Debug.Log("The iframe content can be accessed 👍");
    }
#endif

ExecuteJavaScriptLocally

static bool ExecuteJavaScriptLocally(string javaScript)

Executes the given JavaScript locally in the Unity app's window.

Example

#if UNITY_WEBGL && !UNITY_EDITOR
    // Changes the background color of the Unity app to green.
    WebGLWebView.ExecuteJavaScriptLocally("document.body.style.backgroundColor = 'green';")
#endif

SetUnityContainerElementId

static bool SetUnityContainerElementId(string containerId)

Explicitly sets the HTML element that 2D WebView should use as the Unity app container. 2D WebView automatically detects the Unity app container element if its ID is set to one of the default values of "unityContainer" or "unity-container". However, if your app uses a custom WebGL template that uses a different ID for the container element, you must call this method to set the container element ID. 2D WebView for WebGL works by adding <iframe> elements to the app container, so it's unable to function correctly if it's unable to find the Unity app container element.

Example

void Awake() {
    #if UNITY_WEBGL && !UNITY_EDITOR
        WebGLWebView.SetUnityContainerElementId("your-custom-id");
    #endif
}