Headless Chrome DevTools Protocol Client (RxJava2 + Kotlin)
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
deploy
generator_templates
gradle/wrapper
src
.gitignore
.travis.yml
CODE_OF_CONDUCT.md
CONTRIBUTING.md
LICENSE
README.md
build.gradle Remove profile id Mar 28, 2018
generator.go
gradle.properties Signing configuration Mar 27, 2018
gradlew
gradlew.bat Initial Mar 3, 2017
protocol.json
update.sh

README.md

chrome-reactive-kotlin

Maven Central

chrome-reactive-kotlin is a low level Chrome DevTools Protocol client written in Kotlin and leveraging RxJava2 for easy composability.

Library exposes all protocol domains in a single, cohesive and highly composable API. It supports both headless and standalone Chrome versions and understands BrowserContext from Target domain.

For debugging purposes you can use my other project: chrome-protocol-proxy.

Please note that most up-to-date protocol is used at the moment.

Usage

Add to your Kotlin or Java project (Gradle dependency):

compile group: 'pl.wendigo', name: 'chrome-reactive-kotlin', version: '0.3.+'

Example

package pl.wendigo.chrome

import pl.wendigo.chrome.domain.page.NavigateRequest

fun main(args : Array<String>) {

    val inspector = Inspector.connect("127.0.0.1:9222")
    val protocol = ChromeProtocol.openSession(inspector.openedPages().firstOrError().blockingGet())
    val headless = protocol.headless("about:blank", 1280, 1024).blockingGet()

    println("browserContext: ${headless.browserContextId}")
    println("target: ${headless.targetId}")

    headless.Page.enable().blockingGet()

    val event = headless.Page.navigate(NavigateRequest(url="https://serafin.tech")).flatMap{ (frameId) ->
        headless.Page.frameStoppedLoading().filter {
            it.frameId == frameId
        }
        .take(1)
        .singleOrError()
    }.blockingGet()

    println("page loaded: $event")
}

or if you prefer fully reactive composition:

package pl.wendigo.chrome

import pl.wendigo.chrome.domain.page.NavigateRequest

fun main(args : Array<String>) {

    val loaded = Inspector.connect("127.0.0.1:9222")
        .openedPages()
        .firstOrError()
        .map(InspectablePage::connect)
        .flatMap { protocol ->
            protocol.headless(url = "about:blank", width = 1280, height = 1024)
        }.flatMap { headlessProtocol ->
            headlessProtocol.Page.enable().flatMap {
                headlessProtocol.Page.navigate(NavigateRequest(url = "https://serafin.tech")).flatMap { (frameId) ->
                    headlessProtocol.Page.frameStoppedLoading().filter {
                        it.frameId == frameId
                    }.take(1).singleOrError()
                }
            }
        }

    println("Page was loaded ${loaded.blockingGet()}")
}