Chrome DevTools Kotlin Client is a DevTools client - in Kotlin. It can be used for instrumenting, inspecting, debuging and profiling Chromium, Chrome and other Blink-based browsers. [1]
For more information on DevTools, see https://chromedevtools.github.io/devtools-protocol/.
Note: This API retains full compatibility with the original chrome-devtools-java-client, but all methods are defined as suspend functions, making them non-blocking.
suspend fun main() {
// Create chrome launcher.
val launcher = ChromeLauncher()
// Launch chrome either as headless (true) or regular (false).
val chromeService = launcher.launch(false)
// Create empty tab ie about:blank.
val tab = chromeService.createTab()
// Get DevTools service to this tab
val devToolsService = chromeService.createDevToolsService(tab)
// Get individual commands
val page = devToolsService.page
val tracing = devToolsService.tracing
val dataCollectedList = mutableListOf<Any>()
// Add tracing data to dataCollectedList
tracing.onDataCollected { event: DataCollected ->
dataCollectedList.addAll(event.value)
}
// When tracing is complete, dump dataCollectedList to JSON file.
tracing.onTracingComplete {
// Dump tracing to file.
val path = Paths.get("/tmp/tracing.json")
println("Tracing completed! Dumping to $path")
val om = ObjectMapper()
om.writeValue(path.toFile(), dataCollectedList)
devToolsService.close()
}
page.onLoadEventFired { tracing.end() }
page.enable()
tracing.start()
page.navigate("https://github.com")
}
make verify
make sonar-analysis
Run following:
make download-latest-protocol
This will download browser_protocol.json and js_protocol.json (protocol definitions) from https://github.com/ChromeDevTools/devtools-protocol repo.
| Module | Description | Serialization |
|---|---|---|
| cdt-kotlin-client | Chrome DevTools Kotlin client (Jackson @JsonProperty annotations) |
Jackson |
| cdt-kotlin-client-serialization | Chrome DevTools Kotlin client (kotlinx.serialization @Serializable/@SerialName) |
kotlinx.serialization |
| cdt-kotlin-client-ktor | Ktor-based transport implementation | — |
| cdt-kotlin-protocol-builder | Code generator that produces the client sources from protocol JSON | — |
- Use
cdt-kotlin-clientwhen you need Jackson compatibility (e.g., existing projects that already use Jackson). - Use
cdt-kotlin-client-serializationwhen you prefer kotlinx.serialization — it has zero Jackson/Gson dependency and is a natural fit for Kotlin-first projects.
Make sure you have correct or latest protocol definitions. See Download latest protocol on how to update protocol definitions to latest version.
Run following:
make update-protocol
Run following:
make update-protocol-serialization
# Standard mode (Jackson)
.\bin\generate-kotlin.ps1
# Serialization mode (kotlinx.serialization)
.\bin\generate-kotlin.ps1 -Serialization
# Skip rebuild of the builder JAR
.\bin\generate-kotlin.ps1 -Serialization -SkipBuild
# Custom output directory
.\bin\generate-kotlin.ps1 -Serialization -OutputProject "my-client"This will build the tools for parsing and generating Kotlin files, cdt-kotlin-protocol-builder project. The input for this tool are protocol definitions files: browser_protocol.json and js_protocol.json. The generated Kotlin files will be present in the target module. After building Kotlin files, the target module will be compiled. If everything goes successfully, consider the protocol updated. :)
To go over each module and each source java file to update copyright license header, run:
make update-copyright-license-header
Chrome DevTools Kotlin Client is licensed under the Apache License, Version 2.0. See LICENSE for the full license text.