Created
June 8, 2024 21:34
-
-
Save chr15m/5671491e2757909f3d1797df7ef22111 to your computer and use it in GitHub Desktop.
nbb script to take a screenshot of localhost:8000 in the major browser rendering engines
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns screenshots | |
(:require ["playwright" :as pw] | |
[promesa.core :as p])) | |
; NOTE: you'll need to npm install `nbb` and `playwright` | |
(defn wait-for-network-idle [page] | |
(p/do | |
(.waitForLoadState page "networkidle") | |
(p/delay 100))) ;; Add 100ms delay | |
(defn take-screenshot [browser-type url file-path] | |
(p/let [browser (.launch browser-type) | |
context (.newContext browser) | |
page (.newPage context)] | |
(.goto page url) | |
(wait-for-network-idle page) | |
(.screenshot page (clj->js {:path file-path :fullPage true})) | |
(print (str "wrote " file-path)) | |
(.close browser))) | |
(defn run [url] | |
(print "Taking screenshots") | |
(p/do (take-screenshot (.-chromium pw) url "chromium.png") | |
(take-screenshot (.-firefox pw) url "firefox.png") | |
(take-screenshot (.-webkit pw) url "webkit.png"))) | |
(run "http://localhost:8000") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment