How do I enable debugging on an Android WebView?

NicolasBrondinBernard

Author
@NicolasBrondinBernard

Plugging in your Android phone and opening Google Chrome is no longer enough!

Article published on 11/10/2021, last updated on 10/08/2026

Enabling debug with Chrome

Whether you're building native or hybrid (web+webview) applications on Android, one of the interesting (sometimes essential) features of the environment is being able to debug your WebView content directly in Google Chrome.

With the developer console, just like any web application!

You might think that compiling your application in "debug" mode instead of "release" mode would be enough to enable this option, but that's not the case.

In fact, it's no longer the case since the KitKat version of the OS!

You therefore need to enable this feature directly inside your application, fortunately the activation is very simple, you just need to add these three lines to your controller:

// MainController.java
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
    WebView.setWebContentsDebuggingEnabled(true);
}

But be careful, because this will globally enable debugging for all the webviews in your application (we're calling the static method on the entire class) and it won't take into account your app's build mode (whether the debuggable flag is enabled or not). To handle this properly, it's better to go with this version of the code instead:

// MainController.java
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
    if (0 != (getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE))
    { WebView.setWebContentsDebuggingEnabled(true); }
}

Going further

If you're not familiar with the rest of the process for debugging your hybrid applications with Chrome, I invite you to follow the remaining steps on Google's website: https://developer.chrome.com/docs/devtools/remote-debugging/webviews/


Jonathan Kemper sur Unsplash

Finished reading this article?
Our complete courses
Take it to the next level with our courses!

Complete courses, exercises and certificates to really learn programming!

4.8 average rating

Comments (0)

to leave a comment

No comments yet