Essential Android WebView edit forum

Troubleshooting WebView by printing console messages or by remote debugging

Printing webview console messages to logcat

To handle console messages from web page you can override onConsoleMessage in WebChromeClient:

final class ChromeClient extends WebChromeClient {
    public boolean onConsoleMessage(ConsoleMessage msg) {
            String.format("%s %s:%d", msg.message(), msg.lineNumber(), msg.sourceId())
        return true;

And set it in your activity or fragment:

webView.setWebChromeClient(new ChromeClient());

So this sample page:

    <script type="text/javascript">
        console.log('test message');

will write log ‘test message’ to logcat:

WebView: test message sample.html:4, console.warn() and console.error() are also supported by chrome-client.

Remote debugging android devices with Chrome

Your can remote debug webview based application from you desktop Chrome.

Enable USB debugging on your Android device

On your Android device, open up Settings, find the Developer options section, and enable USB debugging.

Connect and discover your Android device

Open page in chrome following page: chrome://inspect/#devices

From the Inspect Devices dialog, select your device and press inspect. A new instance of Chrome’s DevTools opens up on your development machine.

More detailed guideline and description of DevTools can be found on

Table Of Contents
20 WebView
64 Menu
112 Loader
119 Xposed
132 Colors
135 Fresco
140 AdMob
147 Button
156 Vk SDK
170 XMPP
176 OpenCV
200 FileIO
203 Moshi
217 Paint
231 AIDL
241 JCodec
243 Okio
255 Looper
  ↑ ↓ to navigate     ↵ to select     Esc to close