Android: problem with debugging javascript in webview
Asked Answered
G

2

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.

Gilding answered 1/2, 2011 at 7:34 Comment(3)
Experiencing the same issue on stock HTC Desire HD/Android 2.2.Alcantar
I have HTC Legend. It seems like HTC-specific problem, because on emulator all works fine.Gilding
probably same issue at #5539016Correlate
C
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?

Curator answered 8/6, 2011 at 14:53 Comment(0)
F
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

Fire answered 16/3, 2011 at 15:55 Comment(1)
I have similar code. On emulator it works well. But on device it does not.Gilding

© 2022 - 2024 — McMap. All rights reserved.