• Stars
    star
    130
  • Rank 277,575 (Top 6 %)
  • Language
    Clojure
  • License
    MIT License
  • Created over 7 years ago
  • Updated 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Clojure API for controlling a Chrome DevTools remote

clj-chrome-devtools

Clojars Project Tests

clj-chrome-devtools is a simple library for controlling a headless Chrome with the Chrome DevTools Protocol. The protocol is based on a websocket connection between clojure and chrome. All the functions are automatically generated from the protocol specification JSON files.

Quick start with Babashka

See bb.clj file for a quick script that can be used from Babashka.

Goals

The goal of the project is to provide a general purpose library for using headless chrome, both in production use and in testing scenarios.

The CDP part, which is autogenerated, should be stable and will be updated when CDP protocol changes.

The higher level automation utilities is where most of the work is done and new automation utilities are welcome. PRs welcome, just follow the common pattern of providing two arities: one for using the global automation context and one where it is provided as the first parameter.

API Docs

See codox generated API docs.

All the low-level auto-generated commands from Chrome Devtools Protocol are in clj-chrome-devtools.command.* namespaces. Note: to use the low-level API you need to implement event handlers for listening to data Chrome sends the client.

There is the beginnings of a rudimentary higher level API in clj-chrome-devtools.automation. There is also a clojure.test fixture to run tests with a fresh headless chrome in clj-chrome-devtools.automation.fixture.

Example usage

For using the higher level API for screen scraping and browser testing, see chrome_test.clj file.

The following shows a simple REPL usage, navigating to a page and inspecting content. The connection is the first parameter of all calls. You can also set the connection to use with set-current-connection! and omit the connection parameter for convenience.

clj-chrome-devtools.core> (def c (connect "localhost" 9222))
#'clj-chrome-devtools.core/c
clj-chrome-devtools.core> (require '[clj-chrome-devtools.commands.page :as page]
                                   '[clj-chrome-devtools.commands.dom :as dom])
nil
clj-chrome-devtools.core> (page/navigate c {:url "http://webjure.org/"})
{:frame-id "68439.1"}
clj-chrome-devtools.core> (dom/get-document c {:depth 1})
{:root
 {:children
  [{:node-type 1,
    :node-id 2,
    :backend-node-id 4,
    :parent-id 1,
    :node-name "HTML",
    :node-value "",
    :frame-id "68439.1",
    :local-name "html",
    :child-node-count 2,
    :attributes []}],
  :document-url "http://webjure.org/",
  :node-type 9,
  :base-url "http://webjure.org/",
  :node-id 1,
  :backend-node-id 3,
  :node-name "#document",
  :node-value "",
  :xml-version "",
  :local-name "",
  :child-node-count 1}}
clj-chrome-devtools.core> (use 'clojure.repl)
nil
clj-chrome-devtools.core> (doc dom/get-outer-html)
-------------------------
clj-chrome-devtools.commands.dom/get-outer-html
([] [{:as params, :keys [node-id]}] [connection {:as params, :keys [node-id]}])
  Returns node's HTML markup.

Parameters map keys:
  :node-id              Id of the node to get markup for.

Return map keys:
  :outer-html           Outer HTML markup.
nil
clj-chrome-devtools.core> (dom/get-outer-html c {:node-id 1})
{:outer-html
 "<html><head>\n    <title>Webjure</title>\n  </head>\n  <body>\n    Coming soon-ish!\n  \n\n</body></html>"}

Running ClojureScript test suite with clj-chrome-devtools

The clj-chrome-devtools.cljs.test contains a function that can be used to build and run ClojureScript tests as part of your Clojure test without needing doo plugin or karma installed.

See example in Tuck project.

The build-and-test function is meant to be called inside your test and it will build the specified ClojureScript build that is defined in project.clj (e.g. "test") with an added test runner that requires the specified namespaces and runs tests in them.

More Repositories

1

ripley

Server rendered UIs over WebSockets
Clojure
300
star
2

specql

Automatic PostgreSQL CRUD queries
Clojure
132
star
3

pgprolog

PostgreSQL Prolog language handler
Rust
128
star
4

xtdb-inspector

Web UI for inspecting XTDB (v1) database
Clojure
91
star
5

postgrest-ui

ClojureScript UI components for PostgREST
Clojure
57
star
6

Webjure

Webjure, a web programming framework for Clojure
Clojure
32
star
7

bearsql

Bare words SQL macro for Clojure
Clojure
32
star
8

tuck

Tuck: a micro framework for Reagent apps
Clojure
29
star
9

re-svg-icons

Reagent SVG icons
Clojure
28
star
10

clj-prolog

Clojure interface to Prolog
Clojure
21
star
11

bb-lambda

AWS Lambda custom runtime for Babashka scripts
Clojure
19
star
12

xtdberl

Erlang/Elixir interface to XTDB (v1)
Erlang
17
star
13

REPLey

A web REPL made with Ripley
Clojure
16
star
14

re-html-template

Generate hiccup (reagent/server rendering) components from HTML templates at compile time
Clojure
14
star
15

LiveWeb

LiveWeb: web app framework for Smalltalk
Smalltalk
13
star
16

json-schema

JSON schema validator
Clojure
12
star
17

nrepl-doc-inject

NREPL middleware to inject community docstrings
Clojure
12
star
18

drtest

Declarative Reagent testing library
Clojure
12
star
19

eta-jdbc-example

Simple example of using JDBC from Eta language
Haskell
10
star
20

reagent-leaflet

Use LeafletJS maps as Reagent components
Clojure
9
star
21

pows

Playwright over WebSocket
Clojure
7
star
22

mato

Simple reagent SVG worm game for educational purposes
Clojure
6
star
23

koukku

Yet another small React wrapper with hooks
Clojure
5
star
24

rolf

Reagent OpenLayers Functions: a simple Reagent wrapper for OpenLayers
Clojure
5
star
25

pharo-Pows

Pharo library for using Playwright over WebSocket
Smalltalk
5
star
26

swixt

SWI-Prolog library for XTDB v2
Prolog
5
star
27

widgetshop

Simple Reagent example.
Clojure
4
star
28

asar

Read ASAR archive files from Clojure
Clojure
4
star
29

tulivarasto

Simple Google Cloud Firestore library for Clojure
Clojure
3
star
30

matofs

Simple F# SVG worm game (Fable React)
F#
3
star
31

electric-examples

Electric Clojure examples and experiments (based on starter app)
CSS
2
star
32

pharo-XTDB

XTDB client for Pharo Smalltalk
Smalltalk
2
star
33

raylib-smalltalk

Smalltalk bindings to Raylib
Smalltalk
2
star
34

edn-to-cfn

See: portkey-cloud/edn-to-cfn
Clojure
2
star
35

tuck-remoting

Supplemental remoting library for Tuck: send events between client and server
Clojure
2
star
36

elmato

Simple Elm SVG worm game
Elm
2
star
37

pharo-EDN

Extensible Data Notation library for Pharo Smalltalk
Smalltalk
2
star
38

mappy

An experimental pure Reagent web map library
Clojure
2
star
39

pharo-EmacsKeys

Some emacs like key bindings to make Pharo code editing feel more at home
Smalltalk
2
star
40

fileyard

Trivial file storage
Clojure
1
star
41

jiradash

Emacs JIRA dashboard
Emacs Lisp
1
star
42

iwantmylunch

A simple Swift command line utility to check your Edenred lunch card balance
Swift
1
star
43

aoc2021-smalltalk

Some Advent of Code 2021 learning using Smalltalk
Smalltalk
1
star
44

pharo-Kafka

Pharo bindings to librdkafka C client library.
Smalltalk
1
star
45

express-htmx

CSS
1
star
46

aoc2023-prolog

Advent of Code 2023 in Prolog
Prolog
1
star