Giter Site home page Giter Site logo

boob-sbcm / chrome-reactive-kotlin Goto Github PK

View Code? Open in Web Editor NEW

This project forked from wendigo/chrome-reactive-kotlin

0.0 1.0 0.0 1.28 MB

Headless Chrome DevTools Protocol Client (RxJava2 + Kotlin)

License: Apache License 2.0

Shell 0.28% Go 1.85% HTML 0.99% Kotlin 96.74% Groovy 0.13%

chrome-reactive-kotlin's Introduction

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()}")
}

chrome-reactive-kotlin's People

Contributors

wendigo avatar bai-jie avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.