Code example for ConsoleMessage

Methods: lineNumber, message, messageLevel, sourceId

0
    { 
 
        @Override 
        public boolean onConsoleMessage( ConsoleMessage consoleMessage )
        { 
            if ( consoleMessage.messageLevel() == ConsoleMessage.MessageLevel.ERROR ) {
                Log.e( "JSConsole:", buildConsoleMessageLog( consoleMessage ) );
            } else { 
                Log.d( "JSConsole:", buildConsoleMessageLog( consoleMessage ) );
            } 
            return true; 
        } 
 
    } 
 
    private static String buildConsoleMessageLog( ConsoleMessage consoleMessage )
    { 
        StringBuilder msg = new StringBuilder();
        msg.append( consoleMessage.messageLevel().name() ).
                append( '\t' ).append( consoleMessage.message() ).
                append( '\t' ).append( consoleMessage.sourceId() ).append( " (" ).append( consoleMessage.lineNumber() ).append( ")\n" );
        return msg.toString();
    } 
 
    public static class ChainedWebChromeClient 
            extends WebChromeClient