Android

WebView의 console.log를 logcat으로 보는 방법

Pina Colada 2015. 12. 11. 09:54
Android Kitkat(4.4) 미만 모델에서는
크롬 insepector와 연결해서 디버깅을 할 수 없기 때문에
로그로 디버깅을 해야하지만
 
일반적으로
WebView에서 console.log를 이용해도
Android SDK의 logcat에서는 출력이 되지 않습니다.
 
출력이 가능하기 위해서는

Native에서 추가적인 처리가 필요합니다.

WebView myWebView = (WebView) findViewById(R.id.webview);
myWebView.setWebChromeClient(new WebChromeClient() {
  public boolean onConsoleMessage(ConsoleMessage cm) {
    Log.d("MyApplication", cm.message() + " -- From line "
                         + cm.lineNumber() + " of "
                         + cm.sourceId() );
    return true;
  }
});


출처 :