Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

웹뷰를 오픈했을때 에러 메세지 Json 파싱을 할때 에러가 발생하고 있습니다 #454

Closed
8 tasks
harrywkd5300 opened this issue Nov 1, 2023 · 8 comments
Assignees
Labels
bug Issue type : Bug report no-issue-activity WebView Service : WebView

Comments

@harrywkd5300
Copy link

harrywkd5300 commented Nov 1, 2023

Service

  • [v] WebView
  • AssetManagement
  • Communicator
  • LogViewer
  • Manager
  • UI
  • Profiler
  • Adapter
  • DLST

Version

1.12.1

Describe the bug

안드로이드 기기에서 간혈적으로 웹뷰를 열었을때 Gpm.WebView.Internal.NativeWebView.OnWebViewCallback 부분에서 에러가 발생을 하여 json 파싱을 할때 JsonException : Can't assign value 'ALREADY_OPEN' (type System.String) to type System.Int32 에러가 발생하고 있습니다.

To Reproduce

Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior

A clear and concise description of what you expected to happen.

Screenshots

If applicable, add screenshots to help explain your problem.

Environment

Unity

  • Version 2022.1.24f1

Desktop (please complete the following information):

  • OS: [e.g. iOS]
  • Browser [e.g. chrome, safari]
  • Version [e.g. 22]

Smartphone (please complete the following information):

  • Device: [e.g. iPhone6]
  • OS: [e.g. iOS8.1]
  • Browser [e.g. stock browser, safari]
  • Version [e.g. 22]

Additional context

Add any other context about the problem here.

@harrywkd5300 harrywkd5300 added the bug Issue type : Bug report label Nov 1, 2023
@taehyeon-nhn taehyeon-nhn self-assigned this Nov 1, 2023
@taehyeon-nhn taehyeon-nhn added the WebView Service : WebView label Nov 1, 2023
@taehyeon-nhn
Copy link
Contributor

안녕하세요. @harrywkd5300님.

현재 GPM WebView는 하나만 생성하는 것으로 설정되어,
WebView instance가 존재하는 상태에서 추가 WebView를 생성하면 ALREADY_OPEN 오류가 발생합니다.
WebView instance가 존재하는 상황이 아니라면,
저희가 테스트해 볼 수 있는 오류 발생 상황 또는 Sample code를 공유 부탁드립니다.
특정 디바이스에서 발생한다면 해당 정보도 포함 부탁드립니다.

감사합니다.

@harrywkd5300
Copy link
Author

harrywkd5300 commented Nov 6, 2023

    GpmWebView.ShowUrl( url,
                new GpmWebViewRequest.Configuration()
                {
                    style = GpmWebViewStyle.FULLSCREEN,
                    orientation = GpmOrientation.PORTRAIT,
                    isClearCookie = true,
                    isClearCache = true,
                    backgroundColor = "#FFFFFF",
                    isNavigationBarVisible = true,
                    navigationBarColor = "#4B96E6",
                    title = title,
                    isBackButtonVisible = true,
                    isForwardButtonVisible = true,
                    supportMultipleWindows = true,
                    #if UNITY_IOS
                    contentMode = GpmWebViewContentMode.MOBILE,
                    isAutoRotation = false
                    #endif
                },
                OnCallback,
                new List<string>()
                {
                    "USER_ CUSTOM_SCHEME"
                }
                );

//////////////////////////////////////

   void OnCallback( GpmWebViewCallback.CallbackType callbackType, string data, GpmWebViewError error )
   {
        Debug.Log( "OnCallback: " + callbackType );

        switch( callbackType )
        {
        case GpmWebViewCallback.CallbackType.Open:
            if( error != null )
            {
                Debug.LogFormat( "Fail to open WebView. Error:{0}", error );
            }
            break;
        case GpmWebViewCallback.CallbackType.Close:
            if( error != null )
            {
                Debug.LogFormat( "Fail to close WebView. Error:{0}", error );
            }
            break;
        case GpmWebViewCallback.CallbackType.PageStarted:
            if( string.IsNullOrEmpty( data ) == false )
            {
                Debug.LogFormat( "PageStarted Url : {0}", data );
            }
            break;
        case GpmWebViewCallback.CallbackType.PageLoad:
            if( string.IsNullOrEmpty( data ) == false )
            {
                Debug.LogFormat( "Loaded Page:{0}", data );
            }
            break;
        case GpmWebViewCallback.CallbackType.MultiWindowOpen:
            Debug.Log( "MultiWindowOpen" );
            break;
        case GpmWebViewCallback.CallbackType.MultiWindowClose:
            Debug.Log( "MultiWindowClose" );
            break;
        case GpmWebViewCallback.CallbackType.Scheme:
            if( error == null )
            {
                if( data.Equals( "USER_ CUSTOM_SCHEME" ) == true || data.Contains( "CUSTOM_SCHEME" ) == true )
                {
                    Debug.Log( string.Format( "scheme:{0}", data ) );
                }
            }
            else
            {
                Debug.Log( string.Format( "Fail to custom scheme. Error:{0}", error ) );
            }
            break;
            break;
        case GpmWebViewCallback.CallbackType.GoBack:
            Debug.Log( "GoBack" );
            break;
        case GpmWebViewCallback.CallbackType.GoForward:
            Debug.Log( "GoForward" );
            break;
        case GpmWebViewCallback.CallbackType.ExecuteJavascript:
            Debug.LogFormat( "ExecuteJavascript data : {0}, error : {1}", data, error );
            break;
        }
    }

코드는 이렇게 사용하고 있고 특정기기라기 보다는 와이파이 환경이 느린 상황에서 간혈적으로 발생하고 있습니다.
의문이 드는 것은 오류가 뜨는 것은 오류가 뜨더라도 ALREADY_OPEN 해당 이슈가 발생하였을때 Json 파싱에러가 발생하면서 크래시가 나면서 앱이 종료되는 상황이 있습니다.

@amuyu
Copy link

amuyu commented Jan 9, 2024

ALREADY_OPEN 에러가 발생하는 경우, 에러가 다음과 같이 오는데,,

{"callback":1,"callbackType":0,"error":"{\"domain\":\"WebViewManager\",\"code\":\"ALREADY_OPEN\",\"message\":\"WebView already open.\"}","scheme":"gpmwebview:https://webViewCallback"}

라이브러리의 NativeWebView.cs 파일에서 에러 메시지를 처리하기 위해 위 json을 GpmWebViewError로 변환하면서 JsonException 이 발생합니다.
에러 문자열의 code는 string 형태인데 GpmWebViewError 의 code 는 int라서 exception이 발생합니다.
이에 대한 처리가 필요할 것 같습니다.

NativeWebView.cs

        private void OnWebViewCallback(NativeMessage nativeMessage)
        {
            var callback = NativeCallbackHandler.GetCallback<GpmWebViewCallback.GpmWebViewDelegate>(nativeMessage.callback);

            if (callback != null)
            {
                GpmWebViewError error = null;

                if (string.IsNullOrEmpty(nativeMessage.error) == false)
                {
                    error = JsonMapper.ToObject<GpmWebViewError>(nativeMessage.error);
                }

                GpmWebViewCallback.CallbackType callbackType = (GpmWebViewCallback.CallbackType)nativeMessage.callbackType;
                if (callbackType == GpmWebViewCallback.CallbackType.Close)
                {
                    NativeCallbackHandler.UnregisterCallback(nativeMessage.callback);
                    RestoreOrientation();
                }
                callback(callbackType, nativeMessage.data, error);
            }
        }

GpmWebViewError.cs

public class GpmWebViewError
{
    public string domain;
    public int code;
    public string message;

    public GpmWebViewError error;

    public override string ToString()
    {
        return JsonMapper.ToJson(this);
    }
}

@taehyeon-nhn
Copy link
Contributor

안녕하세요. @amuyu님.

상세한 내용 전달 감사드립니다.
확인 후 코멘트 드리겠습니다.

감사합니다.

Copy link

Stale issue. Please check this issue.

@spin-nhn
Copy link
Contributor

spin-nhn commented Aug 1, 2024

@amuyu 님 안녕하세요.
제보해 주신 내용 수정하여 다음 배포에 수정될 예정입니다.

감사합니다.

Copy link

github-actions bot commented Aug 9, 2024

Stale issue. Please check this issue.

@spin-nhn
Copy link
Contributor

@harrywkd5300 @amuyu

GPMWebView 2.1.0 버전에서 수정되었습니다.
감사합니다.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue type : Bug report no-issue-activity WebView Service : WebView
Projects
None yet
Development

No branches or pull requests

4 participants