- Notifications
You must be signed in to change notification settings - Fork20
Clojure API for controlling a Chrome DevTools remote
License
tatut/clj-chrome-devtools
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
clj-chrome-devtools is a simple library for controlling a headless Chrome with theChrome DevTools Protocol. The protocol is based on a websocket connection betweenclojure and chrome. All the functions are automatically generated from the protocolspecification JSON files.
Seebb.clj file for a quickscript that can be used fromBabashka.
The goal of the project is to provide a general purpose library for using headless chrome, both inproduction 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 andone where it is provided as the first parameter.
See codox generatedAPI docs.
All the low-level auto-generated commands from Chrome Devtools Protocol are inclj-chrome-devtools.command.*namespaces. Note: to use the low-level API you need to implement event handlers for listening to data Chrome sendsthe client.
There is the beginnings of a rudimentary higher level API inclj-chrome-devtools.automation.There is also aclojure.test fixture to run tests with a fresh headless chrome inclj-chrome-devtools.automation.fixture.
For using the higher level API for screen scraping and browser testing, seechrome_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 withset-current-connection! and omit the connection parameter for convenience.
clj-chrome-devtools.core> (defc (connect"localhost"9222))#'clj-chrome-devtools.core/cclj-chrome-devtools.core> (require '[clj-chrome-devtools.commands.page:as page] '[clj-chrome-devtools.commands.dom:as dom])nilclj-chrome-devtools.core> (page/navigate c {:url"http://webjure.org/"}){:frame-id"68439.1"}clj-chrome-devtools.core> (dom/get-document c {:depth1}){:root {:children [{:node-type1,:node-id2,:backend-node-id4,:parent-id1,:node-name"HTML",:node-value"",:frame-id"68439.1",:local-name"html",:child-node-count2,:attributes []}],:document-url"http://webjure.org/",:node-type9,:base-url"http://webjure.org/",:node-id1,:backend-node-id3,:node-name"#document",:node-value"",:xml-version"",:local-name"",:child-node-count1}}clj-chrome-devtools.core> (use 'clojure.repl)nilclj-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.nilclj-chrome-devtools.core> (dom/get-outer-html c {:node-id1}){:outer-html"<html><head>\n <title>Webjure</title>\n </head>\n <body>\n Coming soon-ish!\n\n\n</body></html>"}
Theclj-chrome-devtools.cljs.test contains a function that can be used to build and runClojureScript tests as part of your Clojure test without needingdoo plugin orkarma installed.
Thebuild-and-test function is meant to be called inside your test and it will build the specifiedClojureScript build that is defined inproject.clj (e.g. "test") with an added test runner thatrequires the specified namespaces and runs tests in them.
About
Clojure API for controlling a Chrome DevTools remote
Resources
License
Contributing
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors12
Uh oh!
There was an error while loading.Please reload this page.