Disable WebView messages from logcat output
Asked Answered
R

1

11

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.

Reprehensible answered 10/7, 2012 at 18:50 Comment(0)
K
14

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.

Kneepad answered 15/3, 2013 at 10:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.