-
Notifications
You must be signed in to change notification settings - Fork 4
/
repl.clj
50 lines (44 loc) · 1.62 KB
/
repl.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
(ns cuic.repl
(:require [clojure.pprint :refer [pprint]]
[cuic.core :as c]
[cuic.impl.dom-node :refer [node?]]
[cuic.impl.js-bridge :as js]
[cuic.impl.browser :as browser]))
(defn set-browser!
"Forcefully sets the default browser to the given one so that every core
function is run against this browser."
[browser]
(println "Forcefully changing the default browser. I hope you know what you're doing... ;-)")
(alter-var-root #'c/*browser* (constantly browser))
nil)
(defn swap-config!
"Forcefully updates the default configurations with the given function."
[f & args]
(println "Forcefully changing the default configuration. I hope you know what you're doing... ;-)")
(apply alter-var-root (concat [#'c/*config* f] args))
(println "*** New config ***")
(pprint c/*config*)
nil)
(def default-launch-opts
{:headless false
:additional-arguments {"window-position" "0,35"
"auto-open-devtools-for-tabs" "true"}})
(defn disable-cache!
"Disables cache from the given browser instance"
[browser]
(-> (browser/tools browser)
(.getNetwork)
(.setCacheDisabled true)))
(defn launch-as-default!
"Launches a new (visible) browser and sets it to the default browser."
([opts]
(doto (c/launch! (merge default-launch-opts opts))
(disable-cache!)
(set-browser!)))
([] (launch-as-default! {})))
(defn inspect
"Logs the given DOM nodes to then opened browser's console"
[nodes]
{:pre [(every? node? nodes)]}
(doseq [n nodes]
(js/exec-in n "console.log('\uD83D\uDC26\uD83D\uDD0D', this)")))