Friday, April 25, 2014

How to enable Chrome remote debugging from Web View

Configure WebViews for debugging

The Enable USB web debugging setting in Chrome doesn't affect WebViews. To debug the contents of your WebView, you need to enable it programmatically from within your application by calling setWebContentsDebuggingEnabled, a static method on the WebView class.

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


This setting applies to all of the application's WebViews. Note that web debugging is not affected by the state of the debuggable flag in the application's manifest. If you want to enable web debugging only when debuggable is true, test the flag at runtime.


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

2 comments: