addHandler
inline fun <T> Connection.addHandler(coroutineScope: CoroutineScope, crossinline event: CDP.() -> Flow<T>, crossinline handler: suspend (T) -> Unit): Job
Adds a handler for a specific CDP event.
This is an alias so that you can use cdp the same way as zendriver does:
// add a handler for the consoleAPICalled event with kdriver
tab.addHandler(this, { cdp.runtime.consoleAPICalled }) { event ->
println(event)
}
Content copied to clipboard
That would be equivalent to this with zendriver:
# add a handler for the consoleAPICalled event with zendriver
tab.add_handler(cdp.runtime.ConsoleAPICalled, lambda event: print(event))
Content copied to clipboard
Although you can directly collect the events from the tab (recommended way of doing it):
// add a handler for the consoleAPICalled event with kdriver, directly
launch {
tab.runtime.consoleAPICalled.collect { event ->
println(event)
}
}
Content copied to clipboard
Return
A Job that can be used to cancel the handler.
Parameters
coroutineScope
The coroutine scope in which the handler will run.
event
A lambda that returns a Flow of the event type to listen to.
handler
A suspend function that will be called with each event of the specified type.