Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Clojure API for controlling a Chrome DevTools remote

License

NotificationsYou must be signed in to change notification settings

tatut/clj-chrome-devtools

Repository files navigation

Clojars ProjectTests

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.

Quick start with Babashka

Seebb.clj file for a quickscript that can be used fromBabashka.

Goals

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.

API Docs

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.

Example usage

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

Running ClojureScript test suite withclj-chrome-devtools

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.

Seeexample in Tuck project.

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

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors12

Languages


[8]ページ先頭

©2009-2025 Movatter.jp