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!
JavaScript is disabled in a WebView by default. You can enable it through the WebSettings attached to your WebView .You can retrieve WebSettings with getSettings() , then enable JavaScript with setJavaScriptEnabled() . WebView myWebView = (WebView) findViewById(R.id.webview);
WebView is a special component in Android which serves as kind of built-in browser inside Android applications. If you want to execute HTML, CSS or JavaScript code in your Android app, or you need to allow users visit a URL without leaving your application, WebView is the way to go.
To run logcat and view messages from Android Studio, select View > Tool Windows > Logcat. For more information, see Write and view logs with logcat. The following are some additional resources related to debugging: Remote debugging on Android.
Open an Android WebView in DevTools To display a list of the Android WebViews with debugging turned on that run on your device, go to edge://inspect . To start debugging, under the Android WebView you want to debug, click inspect. Use DevTools in the same way that you use a remote browser tab.
The answer you a 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; } });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With