Background daemon that keeps a Playwright browser alive between CLI calls.
Listens on a Unix domain socket for JSON commands, executes them against the browser, and returns JSON responses. Each command is one JSON line; each response is one JSON line.
Usage: (start-daemon! {:session "default" :headless true}) ;; blocks (daemon-running? "default") ;; check (stop-daemon!) ;; cleanup
Background daemon that keeps a Playwright browser alive between CLI calls.
Listens on a Unix domain socket for JSON commands, executes them against
the browser, and returns JSON responses. Each command is one JSON line;
each response is one JSON line.
Usage:
(start-daemon! {:session "default" :headless true}) ;; blocks
(daemon-running? "default") ;; check
(stop-daemon!) ;; cleanup(auto-launch-browser! {:keys [channel session headless]
:or {channel "chrome" session "default" headless true}})Launches a browser with --remote-debugging-port on a free port. Uses a temp user-data-dir so the user's existing browser stays untouched.
Params:
channel - Browser channel (e.g. 'chrome', 'msedge'). Defaults to 'chrome'.
session - Session name, used for lock file ownership.
headless - Boolean, whether to launch headless.
Returns a map: :cdp-url - CDP endpoint URL (http://127.0.0.1:<port>) :port - The allocated port :browser-pid - PID of the launched browser process :tmp-dir - Path to the temp user-data-dir (for cleanup)
Launches a browser with --remote-debugging-port on a free port. Uses a temp user-data-dir so the user's existing browser stays untouched. Params: `channel` - Browser channel (e.g. 'chrome', 'msedge'). Defaults to 'chrome'. `session` - Session name, used for lock file ownership. `headless` - Boolean, whether to launch headless. Returns a map: :cdp-url - CDP endpoint URL (http://127.0.0.1:<port>) :port - The allocated port :browser-pid - PID of the launched browser process :tmp-dir - Path to the temp user-data-dir (for cleanup)
(cdp-route-lock-owner cdp-url)Returns the owning session name when cdp-url currently has an active
cross-session route lock, otherwise nil. Stale locks are cleared lazily.
Returns the owning session name when `cdp-url` currently has an active cross-session route lock, otherwise nil. Stale locks are cleared lazily.
(daemon-running? session)Checks if a daemon is running for the given session.
Checks if a daemon is running for the given session.
(discover-cdp-endpoint)Auto-discovers a running Chromium-based browser's CDP endpoint. Checks DevToolsActivePort files first (Chrome, Edge, Chromium data dirs + ms-playwright cache), then probes common ports (9222, 9229). Returns a CDP URL string (http:// or ws://) suitable for Playwright connectOverCDP.
Chrome/Edge 136+ ignores --remote-debugging-port without --user-data-dir. Chrome/Edge 144+ chrome://inspect remote debugging uses WebSocket-only (no HTTP).
Auto-discovers a running Chromium-based browser's CDP endpoint. Checks DevToolsActivePort files first (Chrome, Edge, Chromium data dirs + ms-playwright cache), then probes common ports (9222, 9229). Returns a CDP URL string (http:// or ws://) suitable for Playwright connectOverCDP. Chrome/Edge 136+ ignores --remote-debugging-port without --user-data-dir. Chrome/Edge 144+ chrome://inspect remote debugging uses WebSocket-only (no HTTP).
(find-free-cdp-port)Finds an available CDP port starting from 9222. Checks both the OS-level port availability and spel auto-launch lock files to avoid collisions with other sessions. Returns the port number or throws if none found.
Finds an available CDP port starting from 9222. Checks both the OS-level port availability and spel auto-launch lock files to avoid collisions with other sessions. Returns the port number or throws if none found.
(flags-file-path session)Returns the launch flags persistence file path for a session.
Returns the launch flags persistence file path for a session.
(kill-auto-launched-browser! {:keys [port browser-pid tmp-dir]})Kills an auto-launched browser process and cleans up its lock file and temp dir.
Kills an auto-launched browser process and cleans up its lock file and temp dir.
(log-file-path session)Returns the log file path for a session.
Returns the log file path for a session.
(pid-file-path session)Returns the PID file path for a session.
Returns the PID file path for a session.
(read-session-flags session)Reads persisted launch flags for a session from the flags file. Returns a map of flag-name->value, or empty map if file doesn't exist. Used by CLI to recover flags like --cdp without requiring them on every command.
Reads persisted launch flags for a session from the flags file. Returns a map of flag-name->value, or empty map if file doesn't exist. Used by CLI to recover flags like --cdp without requiring them on every command.
(resolve-browser-binary channel)Resolves the filesystem path to a Chrome/Edge binary based on the channel name. Supports: chrome, msedge, chrome-beta, chrome-canary, msedge-beta, msedge-dev. Falls back to 'chrome' if channel is nil. Returns the binary path string, or throws if not found.
Resolves the filesystem path to a Chrome/Edge binary based on the channel name. Supports: chrome, msedge, chrome-beta, chrome-canary, msedge-beta, msedge-dev. Falls back to 'chrome' if channel is nil. Returns the binary path string, or throws if not found.
(socket-path session)Returns the Unix socket path for a session.
Returns the Unix socket path for a session.
(start-daemon! opts)Starts the daemon server. Blocks until shutdown.
Params:
opts - Map:
:session - String (default 'default')
:headless - Boolean (default true)
:browser - String (optional, e.g. 'firefox', 'webkit')
:cdp - String (optional, CDP endpoint URL)
Starts the daemon server. Blocks until shutdown. Params: `opts` - Map: :session - String (default 'default') :headless - Boolean (default true) :browser - String (optional, e.g. 'firefox', 'webkit') :cdp - String (optional, CDP endpoint URL)
(stop-daemon!)Stops the daemon server and cleans up browser resources. Closes server socket first so new CLI invocations fail fast and start a fresh daemon. Only deletes PID/socket files if they still belong to THIS process (prevents nuking a replacement daemon's files).
Stops the daemon server and cleans up browser resources. Closes server socket first so new CLI invocations fail fast and start a fresh daemon. Only deletes PID/socket files if they still belong to THIS process (prevents nuking a replacement daemon's files).
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 |