Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable WebView messages from logcat output

We're using WebViews to display web pages behind a https scheme and intentionally display "insecure content" (non-https resources) on it for performance but the WebView constantly outputs logcat warning messages. Is there anyway to disable/hide them?

It can technically leak sensitive URLs to anything that can read the logcat output, so it would be really great to be able to hide it.

07-10 11:42:56.198: W/Web Console(32423): The page at https://secure_url displayed insecure content from http://insecure_url.

like image 277
Grantland Chew Avatar asked Jul 10 '12 18:07

Grantland Chew


1 Answers

It's possible.

Just override WebViewClient for your WebView like this:

webView.setWebChromeClient(new WebChromeClient() 
{
   @Override
   public boolean onConsoleMessage(ConsoleMessage cm) {
      Log.d("TAG", cm.message() + " at " + cm.sourceId() + ":" + cm.lineNumber());
      return true;
   }
});

You can of course comment out the log line or just create a Log class and disable logging when doing release build.

like image 142
MadDeveloper Avatar answered Nov 20 '22 15:11

MadDeveloper