wendigo / chrome-reactive-kotlin

Headless Chrome DevTools Protocol Client (RxJava3 + Kotlin)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

chrome-reactive-kotlin v0.7.1

Maven Central Javadocs Tests Update Status Dependabot Status

chrome-reactive-kotlin is a low level Chrome DevTools Protocol client written in Kotlin and leveraging RxJava3 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 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

Gradle

build.gradle:

implementation 'pl.wendigo:chrome-reactive-kotlin:0.7.1'

build.gradle.kts:

implementation("pl.wendigo:chrome-reactive-kotlin:0.7.1")

Maven

pom.xml:

<dependency>
  <groupId>pl.wendigo</groupId>
  <artifactId>chrome-reactive-kotlin</artifactId>
  <version>0.7.1</version>
</dependency>

Example

Run headless chrome:

docker container run -d -p 9222:9222 eu.gcr.io/zenika-hub/alpine-chrome:89 --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()
                }
            }
        }
    }
}

About

Headless Chrome DevTools Protocol Client (RxJava3 + Kotlin)

License:Apache License 2.0


Languages

Language:Kotlin 97.9%Language:Go 1.0%Language:Handlebars 0.6%Language:Groovy 0.3%Language:Shell 0.2%