Parag Chauhan
Parag Chauhan

Reputation: 35956

Webview does not show onConsoleMessage in android

I have used webview

with the reference http://developer.android.com/guide/webapps/debugging.html

  myWebView.getSettings().setJavaScriptEnabled(true);

myWebView.setWebChromeClient(new WebChromeClient() {
   public boolean onConsoleMessage(ConsoleMessage cm) {
              Log.d("MyApplication", cm.message() + " -- From line "
                                   + cm.lineNumber() + " of "
                                   + cm.sourceId() );
              return true;
            }
            public void onConsoleMessage(String message, int lineNumber, String sourceID) {
                Log.d("MyApplication", message + " -- From line "
                                     + lineNumber + " of "
                                     + sourceID);
              }
});

but still m not get log Logcat

Please help me out

Upvotes: 4

Views: 5364

Answers (2)

morgan_il
morgan_il

Reputation: 1531

It appears some devices (HTC Desire and some others) with specific OS (mine had 2.3.3) do not display messages in Logcat window and it seems console.log does not work for them. I found a nice workaround using JavaScript Interface to overcome the issue: Android Console via JS interface

Upvotes: 3

Mu-Tsun Tsai
Mu-Tsun Tsai

Reputation: 2534

In my case (I have Samsung Note 4 running Android 6.0), onConsoleMessage is called only if I set

myWebView.setWebContentsDebuggingEnabled(true);

and when I open the Chrome remote device debugger to inspect the webview. But obviously this is not quite helpful since I can already see the console output on the debugger window.

Upvotes: 1

Related Questions