Debugging

You can easily debug KVision applications in most modern browsers (e.g. Chrome or Firefox), which support source maps generated by Kotlin/JS compiler. Source maps allow you to see Kotlin source code in the browser "Sources" panel. You can see line numbers, step through your code, set breakpoints and watch variable values just like with plain JavaScript.

You can also debug KVision application directly in IntelliJ IDEA Ultimate by creating new "JavaScript Debug" configuration pointing to http://localhost:3000 url.

Console.log

Some UI interactions may be tricky to handle with a debugger, and so being able to fall back to console logging is useful. We find it useful to create a debug function, which is turned on and off with a global boolean.

const val DEBUG = true  // in your App class

...

    fun debug(s: String, color: LogType? = null) {
        if (DEBUG) {
            console.log("%c $s", when (color) {
                null -> ""
                LogType.EVENT -> "background: #FF0; color: #000000"
                LogType.ROUTING -> "background: #09F; color: #000000"
                LogType. ... -> "background: #E1FDD2; color: #000000"
            })
        }
    }
        
    enum class LogType {
      EVENT,
      ROUTING,
      ...
    }
    
...

   debug("user hovered element $element", LogType.Event)

Last updated