From de5a0f1568b927cad322eded24744216d44f5694 Mon Sep 17 00:00:00 2001 From: "developing-today[bot]" <5454422+developing-today[bot]@users.noreply.github.com> Date: Thu, 5 Nov 2026 01:32:36 -0600 Subject: [PATCH] feat(browsers): structural CDP for Chromium and Brave on loopback (code#5924) CDP-everywhere audit follow-up to PR #6088 (Helium): the other Chromium-family browsers in the shared desktop config were installed raw, so their DevTools endpoint existed only when a caller passed flags itself. Fleet port convention: 19222 Helium, 19223 Brave, 19224 Chromium, all bound to 127.0.0.1 only (remote path stays loopback + tailscale serve / CONNECT proxy per doc/2026-11-04_remote-gui-access-runbook.md). Chromium gets a bin-only wrapper (its desktop file uses a bare Exec=chromium resolved via PATH; wrapElectronWithFlags cannot be reused because the package symlinks share/applications into chromium-unwrapped and the helper desktop rewrite fails on the read-only target). Brave gets the full wrapper treatment in home/common (binaries wrapped, desktop entries repointed). Wrapper flags precede caller args, so playwright/puppeteer callers passing their own --remote-debugging-port still win. Firefox and Zen (Firefox-family) have no CDP; their remote protocol is WebDriver BiDi, left unconfigured and documented as a gap on #5924. Verified: both new derivations built and inspected (flags present; Brave desktop Exec repointed); changed modules evaluate for hosts amd and nixos. No switch performed -- activation rides the next system switch. --- home/common/default.nix | 40 ++++++++++++++++++++++++++++++++++- nixos/environment/default.nix | 37 ++++++++++++++++++++++++++++++-- 2 files changed, 74 insertions(+), 3 deletions(-) diff --git a/home/common/default.nix b/home/common/default.nix index 7668012477..575dfe873f 100644 --- a/home/common/default.nix +++ b/home/common/default.nix @@ -153,6 +153,44 @@ let install -Dm755 ${opencodeWrapper} $out/bin/opencode ''; }; + + # Brave with structural CDP (code#5924 follow-up): Brave is + # Chromium-family, so it takes the same --remote-debugging flags + # as Helium (19222) and system Chromium (19224); Brave gets + # 19223, loopback-only. Same wrapper shape as + # wrapElectronWithFlags in nixos/environment (binaries wrapped, + # desktop entries repointed at the wrappers) so every launch + # path -- shell or launcher -- carries the flags. Caller-passed + # flags come after wrapper flags and win. + braveCdp = pkgs.symlinkJoin { + name = "${pkgs.brave.name}-cdp"; + paths = [ pkgs.brave ]; + nativeBuildInputs = [ pkgs.makeWrapper ]; + postBuild = '' + for bin in "$out"/bin/*; do + [ -L "$bin" ] || continue + target=$(readlink -f "$bin") + [ -x "$target" ] || continue + rm "$bin" + makeWrapper "$target" "$bin" \ + --add-flags "--remote-debugging-address=127.0.0.1" \ + --add-flags "--remote-debugging-port=19223" + done + + if [ -d "$out/share/applications" ]; then + for f in "$out"/share/applications/*.desktop; do + [ -e "$f" ] || continue + src=$(readlink -f "$f") + base=$(basename "$f") + rm "$f" + sed "s|${pkgs.brave}/bin/|$out/bin/|g" "$src" > "$out/share/applications/$base" + done + fi + ''; + meta = (pkgs.brave.meta or { }) // { + mainProgram = pkgs.brave.meta.mainProgram or null; + }; + }; # The environment the mcpx daemon runs with (services.mcpx.environment # below; the module renders it into the unit). mcpxEnvironment = { @@ -1892,7 +1930,7 @@ in bluez bluez-tools bottom - brave + braveCdp # brave + structural CDP on 127.0.0.1:19223 (code#5924) brig brightnessctl brillo diff --git a/nixos/environment/default.nix b/nixos/environment/default.nix index 869f072dde..07b8334a82 100644 --- a/nixos/environment/default.nix +++ b/nixos/environment/default.nix @@ -261,7 +261,40 @@ let scaleElectron2x = wrapElectronWithFlags "scaled2x" [ "--force-device-scale-factor=2" ]; - # OpenChamber's Electron GUI, built from the developing-today-forks/openchamber fork. + # Chromium with structural CDP (code#5924 follow-up): the fleet + # Chromium entries must always expose the DevTools endpoint on + # loopback -- 19224 (convention: 19222 Helium, 19223 Brave, + # 19224 Chromium). wrapElectronWithFlags cannot be reused here: + # the wrapped chromium package symlinks share/applications into + # chromium-unwrapped's tree, and the helper's in-place desktop + # rewrite fails on the read-only target. No rewrite is needed: + # chromium's desktop file uses a bare `Exec=chromium`, resolved + # through PATH, so wrapping bin/ covers shell and launcher + # launches alike. Wrapper flags precede caller args, so + # automation passing its own --remote-debugging-port + # (playwright/puppeteer via mcpx) still wins. + chromiumPkg = inputs.nixpkgs-unstable.legacyPackages.${system}.chromium; + chromiumCdp = pkgs.symlinkJoin { + name = "${chromiumPkg.name}-cdp"; + paths = [ chromiumPkg ]; + nativeBuildInputs = [ pkgs.makeWrapper ]; + postBuild = '' + for bin in "$out"/bin/*; do + [ -L "$bin" ] || continue + target=$(readlink -f "$bin") + [ -x "$target" ] || continue + rm "$bin" + makeWrapper "$target" "$bin" \ + --add-flags "--remote-debugging-address=127.0.0.1" \ + --add-flags "--remote-debugging-port=19224" + done + ''; + meta = (chromiumPkg.meta or { }) // { + mainProgram = chromiumPkg.meta.mainProgram or null; + }; + }; + + # OpenChamber's Electron GUI, built from the developing-today/openchamber fork. openchamber-desktop = inputs.openchamber.packages.${system}.openchamber-desktop; # OpenChamber CLI/server built from the developing-today-forks/openchamber fork. @@ -1249,7 +1282,7 @@ in # Testing and development tools #beekeeper-studio # electron 31 eol #cypress # electron 37 eol: insecure in this nixpkgs - inputs.nixpkgs-unstable.legacyPackages.${system}.chromium # nixos-unstable channel: cached (master chromium is not) + chromiumCdp # chromium + structural CDP on 127.0.0.1:19224 (code#5924); nixos-unstable channel: cached (master chromium is not) inputs.nixpkgs-unstable.legacyPackages.${system}.chromedriver playwright-driver direnv