2D WebView for WebGL brings the 2D functionality of 3D WebView to Unity's HTML5 WebGL player. It functions by loading web content into an <iframe> element, which works well for many 2D scenarios, but due to browser limitations, it has significant limitations compared to the other 3D WebView packages:
- It only supports Native 2D Mode, so the 2D CanvasWebViewPrefab works, but the 3D WebViewPrefab does not. You can read more about this limitation here.
- It's unable to load websites that block iframes by sending an X-Frame-Options header. For example, many popular sites like Google and Facebook block iframes using X-Frame-Options. You can read more about this limitation and test if a URL is compatible here.
- When the webview's URL has a different domain than the Unity app, most of the IWebView methods become disabled. You can read more about this limitation here. HTML loaded with LoadHtml() also faces this limitation, but an alternative that supports the IWebView methods is to load the HTML from StreamingAssets instead.
- The following IWebView methods are not supported and are ignored at runtime:
- The following IWebView methods have limitations:
- LoadUrl(url, additionalHeaders) is unable to send additional headers due to browser limitations, so it loads the URL without additional headers.
- CanGoBack() and CanGoForward() both return whether the webview can either go back or forward. In other words, both methods return true if the webview can go either back or foward, and both return false if the webview can't go back or forward.
- LoadProgressChanged only indicates the ProgressChangeType.Started and Finished events, and it is unable to indicate the Failed or Updated events.
3D WebView normally works by rendering web content to a texture that is shown in Unity. Unfortunately, WebGL doesn't provide a suitable way to render an iframe to a texture, so 2D WebView for WebGL only supports Native 2D Mode. However, I'm currently developing a separate cloud-based version of 3D WebView that will support 3D in WebGL. If you want me to add you to the waitlist for it, please contact me!
2D WebView for WebGL is unable to load websites that block iframes by sending an X-Frame-Options header. For example, many popular sites like Google and Facebook block iframes using X-Frame-Options. You can determine whether 2D WebView for WebGL can load a given URL by using this URL tester:
For security purposes, browsers prevent a webpage from accessing the content of an iframe if the webpage's URL and the iframe's URL have different domains. For 2D WebView, this means that its IWebView APIs work when the webview's URL matches the domain of the Unity app (for example, when the application loads an HTML file from StreamingAssets or loads a different webpage hosted on your own domain), but most IWebView APIs do not work if the webview's URL is from a different domain (for example, bing.com or any other 3rd party site). When the IWebView APIs are disabled, the user can still click, scroll, and type into the webview directly, but the application cannot interact with the affected IWebView APIs programmatically.
The following IWebView APIs only work when the webview's URL matches the domain of the Unity app:
Other notes about this limitation:
LoadHtml() works by loading content as a data URL, which browsers also consider as a different domain. So, HTML loaded with LoadHtml() also faces this limitation, but an alternative that supports the IWebView methods is to load the HTML from StreamingAssets instead.
An application can check check whether the IWebView APIs listed above are enabled at any time by calling WebGLWebView.CanAccessIFrameContent().