Get Javascript console when emulating WebView app
Asked Answered
L

2

40

I'm pretty new to Android Dev, I'm trying to create a WebView based app. I got the basics, I emulate the app directly on my phone and wanted to know if there is a way to get a Javascript console like in Chrome PC version.

My device is running Android 4.2.1 API Level 17. I can't emulate app on my computer, it doesn't work.

I've already watched this topic on Stackoverflow, but hasn't helped me.

So, what I tried (examples from the Stackoverflow topic) :

  • Remote debugging from my device to my computer : I can't cause my device is running Android 4.2.1 and need, at least, Android 4.4+.

  • JavaScript Console : I can't access and didn't implemented a browser bar into my WebView app (and don't want to implement one...)

  • Original Answer : I put some console.log('test') and console.error('test') on a window.onload function to see if I can find them on the logcat and ADB logs but I can't find them, even if I put adb logcat to search them.

Can someone help me? I really don't know how to get a console, and really need it...

Thanks!

Libeler answered 17/5, 2015 at 20:7 Comment(0)
N
74

The answer you are referring to is for Android Browser app, not for WebView component.

In order to get output from console.log() family of functions, you need to set a WebChromeClient for your WebView and override onConsoleMessage() (doc) method, like this:

webView.setWebChromeClient(new WebChromeClient() {
    @Override
    public boolean onConsoleMessage(ConsoleMessage consoleMessage) {
        android.util.Log.d("WebView", consoleMessage.message());
        return true;
    }
});
Natasha answered 18/5, 2015 at 1:55 Comment(4)
Any chances to do the same for ancestors of the regular web client class?Lactometer
@mikhail-naganov: Do you know how you could also print arrays []? Currently I'm getting [object Object],[object Object],...Heaviness
Answer to my question hereHeaviness
its deprecated nowMundt
A
0

Go to this url on chrome - chrome://inspect/#devices

Select "inspect" option in front of device item.

Apart answered 23/5 at 7:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.