Platform detection and CDP discovery utilities. Pure functions with no dependency on daemon state, browser sessions, or SCI context.
Extracted from daemon.clj to break the circular dependency between sci_env.clj (which needs WSL + CDP functions for the spel namespace) and daemon.clj (which requires sci_env.clj for evaluation).
Both daemon.clj and sci_env.clj can safely require this namespace.
Platform detection and CDP discovery utilities. Pure functions with no dependency on daemon state, browser sessions, or SCI context. Extracted from daemon.clj to break the circular dependency between sci_env.clj (which needs WSL + CDP functions for the spel namespace) and daemon.clj (which requires sci_env.clj for evaluation). Both daemon.clj and sci_env.clj can safely require this namespace.
(cdp-candidate-hosts)Returns the list of hosts to probe for CDP endpoints. Default: ["127.0.0.1"]. Under WSL with a resolvable gateway: ["127.0.0.1" "<gateway-ip>"] — loopback first for the fast path on mirrored networking, gateway second for NAT fallback.
Returns the list of hosts to probe for CDP endpoints. Default: ["127.0.0.1"]. Under WSL with a resolvable gateway: ["127.0.0.1" "<gateway-ip>"] — loopback first for the fast path on mirrored networking, gateway second for NAT fallback.
Default TCP ports scanned when auto-discovering a running CDP browser. Single source of truth — referenced from daemon.clj, sci_env.clj, and the discover-cdp default below.
Default TCP ports scanned when auto-discovering a running CDP browser. Single source of truth — referenced from daemon.clj, sci_env.clj, and the discover-cdp default below. - 9222: Chrome / Edge / Chromium default --remote-debugging-port - 9223: common Windows proxy fallback when 9222 is already bound - 9229: Node.js inspector / Electron devtools
(discover-cdp)(discover-cdp ports timeout-ms)Auto-discovers a running CDP browser by probing candidate hosts and common ports. Returns the first successful probe result (a map with :host :port :browser :ws-url), or nil if no browser is found.
Probes [hosts] × [ports] with the given timeout per probe. Hosts
are determined by cdp-candidate-hosts (WSL-aware). Default ports
come from common-cdp-ports.
Auto-discovers a running CDP browser by probing candidate hosts and common ports. Returns the first successful probe result (a map with :host :port :browser :ws-url), or nil if no browser is found. Probes [hosts] × [ports] with the given timeout per probe. Hosts are determined by `cdp-candidate-hosts` (WSL-aware). Default ports come from `common-cdp-ports`.
(parse-proc-net-route-gateway route-table)Pure: given the text of /proc/net/route, returns the default route's
gateway as a dotted quad, or nil when the table holds no usable default
route.
The kernel stores the gateway as a little-endian 32-bit hex string, so
reversing the byte pairs and joining with dots yields the dotted-quad
form. A default route with gateway 00000000 (0.0.0.0) is on-link and
points at no host, so it is skipped like any other unusable row.
Pure: given the text of `/proc/net/route`, returns the default route's gateway as a dotted quad, or nil when the table holds no usable default route. The kernel stores the gateway as a little-endian 32-bit hex string, so reversing the byte pairs and joining with dots yields the dotted-quad form. A default route with gateway `00000000` (0.0.0.0) is on-link and points at no host, so it is skipped like any other unusable row.
(probe-cdp host port timeout-ms)Probes http://<host>:<port>/json/version and returns a map with :host, :port, :browser, :ws-url on success, or nil on failure.
This is the canonical CDP liveness check used by both the daemon's auto-discovery and SCI's cdp-connect. Having it in one place prevents probe logic from drifting between the two call-sites.
Probes http://<host>:<port>/json/version and returns a map with :host, :port, :browser, :ws-url on success, or nil on failure. This is the canonical CDP liveness check used by both the daemon's auto-discovery and SCI's cdp-connect. Having it in one place prevents probe logic from drifting between the two call-sites.
(read-proc-net-route)Returns the text of /proc/net/route, or nil when it cannot be read.
Reads through Files/readString and not slurp: this file reports
length 0 and the WSL2 kernel's procfs answers the small chunked reads an
InputStreamReader performs with IOException: Invalid argument, so slurp
and line-seq both fail there while one NIO read of the whole file succeeds
(proven in the WSL <-> Windows CDP diagnostic job). Stays pure-file, so no
ip route subprocess and no native-image trouble.
Returns the text of `/proc/net/route`, or nil when it cannot be read. Reads through `Files/readString` and not `slurp`: this file reports `length 0` and the WSL2 kernel's procfs answers the small chunked reads an `InputStreamReader` performs with `IOException: Invalid argument`, so `slurp` and `line-seq` both fail there while one NIO read of the whole file succeeds (proven in the WSL <-> Windows CDP diagnostic job). Stays pure-file, so no `ip route` subprocess and no native-image trouble.
(wsl-default-gateway-ip)Returns the default-gateway IP as seen from inside WSL (which under classic NAT networking IS the Windows host), or nil if we're not in WSL / can't determine it.
Returns the default-gateway IP as seen from inside WSL (which under classic NAT networking IS the Windows host), or nil if we're not in WSL / can't determine it.
(wsl?)Returns true when running inside Windows Subsystem for Linux. Checks /proc/version for "microsoft"/"WSL" markers and the WSL_DISTRO_NAME env var set by wsl.exe — either is sufficient.
Returns true when running inside Windows Subsystem for Linux. Checks /proc/version for "microsoft"/"WSL" markers and the WSL_DISTRO_NAME env var set by wsl.exe — either is sufficient.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |