Can't See WebView on Android
Nobody has claimed this yet.
- Dominant language
- Objective-C++
- Stars
- 2.7k
- Forks
- 734
- Avg merge
- 11h 39m
- Merged PRs (30d)
- 1
Description
I am using the WebView in Unity Editor and iOS just fine but every time I build to Android I'm getting a 401 or 404 error.
Below is the code that im using to open the Webview. I have hardware acceleration set to true and allow clear text to true with no luck.
I am using Unity 6000.3.14f1, Android Minimum SDK 26.
Please help
` IEnumerator OpenPaymentWebViewCoroutine(string mersoResponse, string itemName, string price, Action<string> OnSuccess, Action<string> OnFailed)
{
var json = JsonUtility.FromJson<MersoResponse>(mersoResponse);
var checkoutUrl = $"http://merso-game-api.azurewebsites.net/api/payment/checkout" +
$"?clientSecret={UnityWebRequest.EscapeURL(json.clientSecret)}" +
$"&itemName={UnityWebRequest.EscapeURL(itemName)}" +
$"&amount={price}";
Debug.Log(" Opening WebView: " + checkoutUrl);
// Destroy existing WebView if any
if (_webView != null)
{
Destroy(_webView);
_webView = null;
}
var webViewGO = new GameObject("WebViewObject");
_webView = webViewGO.AddComponent<WebViewObject>();
_webView.Init(
cb: (msg) =>
{
Debug.Log($"CallFromJS: {msg}");
if (msg.Contains("PAYMENT_SUCCESS"))
{
Debug.Log(" Payment successful!");
GrantItemToPlayer(OnSuccess, itemName, price);
CloseWebView();
}
else if (msg.Contains("PAYMENT_CANCELLED"))
{
Debug.Log("Payment cancelled");
CloseWebView();
OnFailed.Invoke("Payment Cancelled");
}
},
err: (msg) =>
{
Debug.LogError($"WebView error: {msg}");
CloseWebView();
OnFailed.Invoke("Payment Cancelled");
},
httpErr: (msg) =>
{
Debug.LogError($"WebView HTTP error: {msg}");
CloseWebView();
OnFailed.Invoke("Payment Cancelled");
},
started: (msg) =>
{
Debug.Log($"WebView started: {msg}");
if (msg.Contains("PAYMENT_SUCCESS"))
{
GrantItemToPlayer(OnSuccess, itemName, price);
CloseWebView();
}
else if (msg.Contains("PAYMENT_CANCELLED"))
{
CloseWebView();
OnFailed.Invoke("Payment Cancelled");
}
},
hooked: (msg) =>
{
Debug.Log($"WebView hooked: {msg}");
},
ld: (msg) =>
{
Debug.Log($"WebView loaded: {msg}");
// Inject Unity bridge JS — required for Android and older iOS
#if UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX || UNITY_IOS
var js = @"
if (!(window.webkit && window.webkit.messageHandlers)) {
window.Unity = {
call: function(msg) {
window.location = 'unity:' + msg;
}
};
}
";
#elif UNITY_ANDROID
var js = @"
window.Unity = {
call: function(msg) {
window.location = 'unity:' + msg;
}
};
";
#else
var js = "";
#endif
_webView.EvaluateJS(js);
},
//androidForceDarkMode: 0,
enableWKWebView: true,
wkContentMode: 0,
wkAllowsLinkPreview: false
);
// Wait for WebView to fully initialize before loading URL
while (!_webView.IsInitialized())
{
yield return null;
}
_webView.SetMargins(0, 0, 0, 0);
_webView.SetTextZoom(100); // Android only
_webView.SetVisibility(true);
_webView.LoadURL(checkoutUrl);
}
``
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at OpenPaymentWebViewCoroutine and inspect the Android WebViewObject initialization, LoadURL call, and logged checkoutUrl in an Android build. Reproduce while capturing the WebView HTTP and error callbacks, then compare the requested URL and response status with the editor and iOS behavior. Done means the Android build loads the checkout page without the reported 401/404 and payment callbacks still work.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, csharp, unity
- Domain
- mobile-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100