WebView displays web content within your Unity mobile application
Essential Kit wraps native iOS WKWebView and Android WebView into a single Unity interface. WebView instances can display URLs, HTML strings, and local files with full JavaScript support.
Single-instance model – Essential Kit surfaces one active web view at a time. Create it once, reuse it, and hide it when not in use.
Frames and styles – Choose between full-screen, normalized, or pixel-perfect frames and pick the style (Default, Popup, Browser) that matches your UX.
Content sources – Web views can render remote URLs, inline HTML strings, or local files bundled with your game.
JavaScript bridge – RunJavaScript executes scripts asynchronously and custom URL schemes let the page talk back to Unity.
Lifecycle – Register events for load, show, hide, and URL scheme matches so you can pause gameplay and resume when the user closes the web content.
Import Namespaces
Event Registration
Register for web view events in OnEnable and unregister in OnDisable:
Event
Trigger
OnShow
Web view becomes visible on screen
OnHide
Web view is hidden from screen
OnLoadStart
Web page begins loading
OnLoadFinish
Web page finishes loading (or fails with error)
OnURLSchemeMatchFound
Custom URL scheme is detected in web content
Creating a WebView Instance
Why WebView Instances are Needed
WebView instances represent individual web views with their own settings, content, and state. Create an instance before loading any web content.
Single Instance: Essential Kit supports one active web view at a time. Creating a new instance replaces any existing web view.
Setting Frame Size
Configure web view size and position before showing:
Full Screen
Normalized Coordinates (0.0 to 1.0)
Screen Pixel Coordinates
Appearance Styles
WebView supports three visual styles with different controls:
Default Style
No controls - clean web content display. Ideal for ads or embedded content.
Popup Style
Close button in top-right corner. User can dismiss web view by tapping.
Browser Style
Full browser controls: back, forward, reload, and close buttons.
Button
Action
Back
Navigate to previous page in history
Forward
Navigate to next page in history
Reload
Refresh current page
Close
Hide the web view
Loading Content
Loading Web URLs
Loading HTML Strings
Loading Local HTML Files
Loading Binary Data
Showing and Hiding WebView
Manual Show/Hide
Auto-Show on Load
Handling Show/Hide Events
JavaScript Execution
Enabling JavaScript
Running JavaScript Code
JavaScript with Parameters
Web-to-Unity Communication
Understanding URL Schemes
URL schemes enable web content to send messages to Unity. Register a custom scheme (like mygame://) and Essential Kit intercepts matching URLs.
Registering URL Schemes
Parsing URL Parameters
Controlling Web View
Reload Current Page
Stop Loading
Clear Cache
ClearCache() Impact: Clearing cache affects all web view instances globally, not just the current one. Use carefully as it may slow down subsequent page loads.
Monitoring Load Progress
Track Loading State
Data Properties
Property
Type
Notes
WebView.URL
string
Last URL that finished loading. Useful for analytics or resuming content after a hide/show cycle.
WebView.IsLoading
bool
true while the page is still loading. Pair it with Progress to drive loading indicators.
WebView.Progress
double
Normalized progress (0–1) reported by native web views.
WebView.ScalesPageToFit
bool
Enable to allow pinch-to-zoom and automatic scaling on both platforms.
WebView.CanBounce
bool
Controls the iOS rubber-band effect. Disable for full-screen kiosk experiences.
WebView.BackgroundColor
Color
Fills the view while content is loading—set it to match your brand palette.
Core APIs Reference
API
Purpose
Returns
WebView.CreateInstance(settings)
Create new web view instance
WebView instance
webView.SetFullScreen()
Set web view to full screen
void
webView.SetNormalizedFrame(rect)
Set size using normalized coordinates
void
webView.LoadURL(url)
Load web URL into web view
void
webView.LoadHtmlString(html)
Load HTML string into web view
void
webView.LoadData(data, mimeType, encoding)
Load binary data into web view
void
webView.Show()
Display web view on screen
void
webView.Hide()
Hide web view from screen
void
webView.RunJavaScript(script, callback)
Execute JavaScript and get result
void - result via callback
webView.AddURLScheme(scheme)
Register custom URL scheme for web-to-Unity messaging
void
webView.Reload()
Reload current page
void
webView.StopLoading()
Cancel current page load
void
webView.ClearCache()
Clear all cached web content
void
Error Handling
Handle load errors in the OnLoadFinish event:
Common error scenarios:
No Internet: Network connection unavailable
Invalid URL: Malformed URL or unreachable host
SSL Error: Certificate validation failure (HTTPS)
Timeout: Page took too long to load
Advanced: Manual Initialization
Manual initialization is only needed for specific runtime scenarios. For most games, Essential Kit's automatic initialization handles everything. Skip this section unless you need runtime configuration or per-instance custom settings.
Understanding Manual Initialization
Default Behavior: Essential Kit automatically initializes WebView using global settings from the ScriptableObject configured in Unity Editor.
Advanced Usage: Override settings at runtime or per-instance when you need:
Dynamic camera/microphone permissions based on web content
Different back button behavior for different web views
Server-driven feature configuration
Implementation
Configure global settings:
Create instance with custom settings:
Call Initialize() once before creating instances. Most games should use the standard setup configured in Essential Kit Settings instead.
void LoadAndAutoShow()
{
webView = WebView.CreateInstance();
webView.SetFullScreen();
webView.AutoShowOnLoadFinish = true; // Show automatically when loaded
webView.LoadURL(URLString.URLWithPath("https://www.example.com"));
}
void OnWebViewShow(WebView view)
{
if (webView == view)
{
Debug.Log("WebView is now visible");
Debug.Log("Pause gameplay while the web view is active.");
}
}
void OnWebViewHide(WebView view)
{
if (webView == view)
{
Debug.Log("WebView was hidden");
Debug.Log("Resume gameplay after closing the web view.");
}
}
int ParseScoreFromURL(string url)
{
// Example: mygame://level-complete?score=1500
var uri = new System.Uri(url);
string query = uri.Query.TrimStart('?');
var parameters = System.Web.HttpUtility.ParseQueryString(query);
return int.Parse(parameters["score"]);
}
void ReloadPage()
{
webView.Reload();
Debug.Log("Reloading web page");
}
void CancelLoading()
{
webView.StopLoading();
Debug.Log("Stopped loading web page");
}