gree / gree/unity-webview

in case web page show alert "This site is trying to open another application." alert not shown inside WebView window (works well on chrome mobile)

Open
#1,048 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Objective-C++
Stars
2.7k
Forks
734
Avg merge
11h 39m
Merged PRs (30d)
1

Description

page https://myhome2.cfc.io/wc/

code:

WebViewObject webViewObject;
IEnumerator StartWebView()
{
webViewObject = (new GameObject("WebViewObject")).AddComponent();
webViewObject.Init(
cb: (msg) =>
{
Debug.Log(string.Format("CallFromJS[{0}]", msg));
},
err: (msg) =>
{
Debug.Log(string.Format("CallOnError[{0}]", msg));
},
httpErr: (msg) =>
{
Debug.Log(string.Format("CallOnHttpError[{0}]", msg));
},
started: (msg) =>
{
Debug.Log(string.Format("CallOnStarted[{0}]", msg));
},
hooked: (msg) =>
{
Debug.Log(string.Format("CallOnHooked[{0}]", msg));
},
cookies: (msg) =>
{
Debug.Log(string.Format("CallOnCookies[{0}]", msg));
},
ld: (msg) =>
{
Debug.Log(string.Format("CallOnLoaded[{0}]", msg));
#if UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX || UNITY_IOS
// NOTE: the following js definition is required only for UIWebView; if
// enabledWKWebView is true and runtime has WKWebView, Unity.call is defined
// directly by the native plugin.
#if true
var js = @"
if (!(window.webkit && window.webkit.messageHandlers)) {
window.Unity = {
call: function(msg) {
window.location = 'unity:' + msg;
}
};
}
";
#else
// NOTE: depending on the situation, you might prefer this 'iframe' approach.
// cf. https://github.com/gree/unity-webview/issues/189
var js = @"
if (!(window.webkit && window.webkit.messageHandlers)) {
window.Unity = {
call: function(msg) {
var iframe = document.createElement('IFRAME');
iframe.setAttribute('src', 'unity:' + msg);
document.documentElement.appendChild(iframe);
iframe.parentNode.removeChild(iframe);
iframe = null;
}
};
}
";
#endif
#elif UNITY_WEBPLAYER || UNITY_WEBGL
var js = @"
window.Unity = {
call:function(msg) {
parent.unityWebView.sendMessage('WebViewObject', msg);
}
};
";
#else
var js = "";
#endif
webViewObject.EvaluateJS(js + @"Unity.call('ua=' + navigator.userAgent)");
},
//transparent: false,
//zoom: true,
//ua: "custom user agent string",
//radius: 0, // rounded corner radius in pixel
//// android
//androidForceDarkMode: 0, // 0: follow system setting, 1: force dark off, 2: force dark on
//// ios
enableWKWebView: true
//wkContentMode: 0, // 0: recommended, 1: mobile, 2: desktop
//wkAllowsLinkPreview: true,
//// editor
//separated: false
);
#if UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX
webViewObject.bitmapRefreshCycle = 1;
#endif
// cf. https://github.com/gree/unity-webview/pull/512
// Added alertDialogEnabled flag to enable/disable alert/confirm/prompt dialogs. by KojiNakamaru · Pull Request #512 · gree/unity-webview
webViewObject.SetAlertDialogEnabled(true);

        // cf. https://github.com/gree/unity-webview/pull/728
        //webViewObject.SetCameraAccess(true);
        //webViewObject.SetMicrophoneAccess(true);

        // cf. https://github.com/gree/unity-webview/pull/550
        // introduced SetURLPattern(..., hookPattern). by KojiNakamaru · Pull Request #550 · gree/unity-webview
        //webViewObject.SetURLPattern("", "^https://.*youtube.com", "^https://.*google.com");

        // cf. https://github.com/gree/unity-webview/pull/570
        // Add BASIC authentication feature (Android and iOS with WKWebView only) by takeh1k0 · Pull Request #570 · gree/unity-webview
        //webViewObject.SetBasicAuthInfo("id", "password");

        //webViewObject.SetScrollbarsVisibility(true);

        webViewObject.SetMargins(5, 100, 5, 100);// Screen.height / 50);
        webViewObject.SetTextZoom(100);  // android only. cf. https://stackoverflow.com/questions/21647641/android-webview-set-font-size-system-default/47017410#47017410
        webViewObject.SetVisibility(true);
        webViewObject.LoadURL("https://myhome2.cfc.io/wc/");

        yield break;

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing https://myhome2.cfc.io/wc/ with the shown WebViewObject.Init, SetAlertDialogEnabled(true), and LoadURL calls, comparing the result with Chrome mobile. Inspect the platform-specific WebView handling for alerts and attempts to open another application; done means the alert appears inside the WebView window as expected.

Written by the indexing model from the issue text.

Assessment

Tech stack
unity
Domain
mobile-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.