Popularity
4.4
Stable
Activity
0.0
Stable
74
7
12

Programming language: Kotlin
License: Apache License 2.0
Tags: Browsers    
Latest version: v0.6.1
Add another 'Browsers' Library

README

chrome-reactive-kotlin

Maven Central Javadocs Build Status Update Status Dependabot Status

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 supports creating isolated environments via BrowserContext from [Target]((https://chromedevtools.github.io/debugger-protocol-viewer/tot/Target/)) domain and flatted sessions mode (see: http://crbug.com/991325).

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.

Documentation can be found on https://wendigo.github.io/chrome-reactive-kotlin/.

Usage

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

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

Example

Run headless chrome:

docker container run -d -p 9222:9222 zenika/alpine-chrome --no-sandbox --remote-debugging-address=0.0.0.0 --remote-debugging-port=9222 about:blank

And now execute:

import pl.wendigo.chrome.api.page.NavigateRequest

fun main() {
    val chrome = Browser.builder()
        .withAddress("127.0.0.1:9222")
        .build()

    chrome.use { browser ->
        browser.target("about:blank").use { target ->
            await {
                target.Page.enable()
            }

            await {
                target.Page.navigate(NavigateRequest(url = "https://github.com/wendigo/chrome-reactive-kotlin")).flatMap { (frameId) ->
                    target.Page.frameStoppedLoading().filter {
                        it.frameId == frameId
                    }.take(1).singleOrError()
                }
            }
        }
    }
}