22

I have some javascript running in WebView, and I want to receive console messages about errors in JS. In accordance with the instructions at http://developer.android.com/guide/webapps/debugging.html I overrided methods

WebChromeClient.onConsoleMessage(String message, int lineNumber, String sourceID)

and

WebChromeClient.onConsoleMessage(ConsoleMessage cm),

redirecting messages to logcat. In android 2.1 it works well, but in android 2.2 none of this methods are called.

What I am doing wrong?

Thanks.

3
  • Experiencing the same issue on stock HTC Desire HD/Android 2.2. Commented Mar 27, 2011 at 16:17
  • I have HTC Legend. It seems like HTC-specific problem, because on emulator all works fine. Commented Mar 28, 2011 at 8:38
  • probably same issue at stackoverflow.com/questions/5538516/… Commented Apr 30, 2011 at 21:25

2 Answers 2

7

It seems that HTC disabled console.log on Android 2.2 devices. check out this post:

How to display console.log() output in PhoneGap app using Eclipse and HTC Desire HD?

Sign up to request clarification or add additional context in comments.

Comments

6

I just tested on 2.2 (level 8). It's working fine. Not sure why you're not seeing it. I would validate the setting of ChromeClient.

js contains...

console.log("Hello World");
console.error("Serious");

ChromeClient contains

    @Override
public void onConsoleMessage(String message, int lineNumber, String sourceID) {
    // TODO Auto-generated method stub
    Log.v("ChromeClient", "invoked: onConsoleMessage() - " + sourceID + ":"
            + lineNumber + " - " + message);
    super.onConsoleMessage(message, lineNumber, sourceID);
}

@Override
public boolean onConsoleMessage(ConsoleMessage cm) {
    Log.v("ChromeClient", cm.message() + " -- From line "
            + cm.lineNumber() + " of "
            + cm.sourceId() );
    return true;
}

Log contains 03-16 15:53:12.309: VERBOSE/ChromeClient(595): Hello World -- From line 24 of file:///android_asset/base.js 03-16 15:53:12.309: VERBOSE/ChromeClient(595): Serious -- From line 25 of file:///android_asset/base.js

1 Comment

I have similar code. On emulator it works well. But on device it does not.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.