Martin Kavalar / Sep 03 2018
Remix of 📸 Screenshotting with Sparkledriver by Martin Kavalar
📸 Screenshotting cljdoc
📸 Screenshotting cljdoc
Trying out Sparkledriver to take screenshots with the built-in webkit browser that's bundled with the JDK.
1. Sparkledriver
1.
Sparkledriver
We start by requring sparkledriver.
(require '[sparkledriver.browser :refer [with-browser make-browser fetch!]]) (require '[sparkledriver.element :refer [screenshot]]) (require '[clojure.java.io :as io])
Let's create a browser and a helper function.
(def browser (make-browser)) (defn preview [url] (-> (fetch! browser url) screenshot io/file (io/copy (io/file "/results/screenshot.png"))))
And, let's shoot! 📸
(preview "https://cljdoc.xyz/d/ring/ring-core/1.7.0-RC2/doc/readme")
(use '[clojure.java.shell :only [sh]]) (defn screenshot [url] (sh "google-chrome" "--headless" "--disable-gpu" "--no-sandbox" "--window-size=960,720" "--hide-scrollbars" "--screenshot=/results/screenshot.png" url))
(screenshot "https://cljdoc.xyz/d/ring/ring-core/1.7.0-RC2/doc/readme")