From fa48228ef4d8ea13dfb0d9d252c1b22ffb678dec Mon Sep 17 00:00:00 2001 From: Antigravity Agent Date: Sat, 3 Oct 2026 00:53:04 -0400 Subject: [PATCH] NetVM: CDP on by default (deterministic port), --headless mode, netvm-cdp.sh helper --- bin/netvm-cdp.sh | 11 +++++++++++ bin/netvm-chrome.sh | 44 +++++++++++++++++++++++++++++++++----------- bin/netvm-names.sh | 1 + 3 files changed, 45 insertions(+), 11 deletions(-) create mode 100755 bin/netvm-cdp.sh diff --git a/bin/netvm-cdp.sh b/bin/netvm-cdp.sh new file mode 100755 index 0000000..d7bdb32 --- /dev/null +++ b/bin/netvm-cdp.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env bash +# netvm-cdp.sh — show how to reach a profile's CDP endpoint. +set -euo pipefail +SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" +. "$SCRIPT_DIR/netvm-names.sh" +netvm_names "${1:?usage: netvm-cdp.sh }" +TAIL_IP=$(tailscale ip -4 2>/dev/null | head -1) +echo "profile: $NODE" +echo "cdp: http://$PEER_IP:$CDP_PORT/json/list (from this host)" +echo "remote: ssh -L $CDP_PORT:$PEER_IP:$CDP_PORT super@${TAIL_IP:-}" +echo "launch: netvm-chrome.sh $NODE [--headless] (CDP on by default)" diff --git a/bin/netvm-chrome.sh b/bin/netvm-chrome.sh index 44d360c..5c51c64 100755 --- a/bin/netvm-chrome.sh +++ b/bin/netvm-chrome.sh @@ -1,18 +1,40 @@ #!/usr/bin/env bash -# netvm-chrome.sh [url] — launch a chrome-box profile inside its -# dedicated NetVM netns. 1:1: profile = node = warp identity = egress IP. +# netvm-chrome.sh [--headless] [--cdp-port N|--no-cdp] [url] +# Launch a chrome-box profile inside its dedicated NetVM netns. +# 1:1: profile = node = warp identity = egress IP. +# CDP is on by default (deterministic port) so agents can automate the +# session via Playwright/Puppeteer; --headless runs without a display. # Run as your normal user (uses sudo -n only for allowlisted netns ops). set -euo pipefail -PROFILE="${1:?usage: netvm-chrome.sh [url]}" -URL="${2:-}" -NODE="$PROFILE" NETVM_BIN="$(cd "$(dirname "$0")" && pwd)" +. "$NETVM_BIN/netvm-names.sh" +HEADLESS=0; CDP_OVERRIDE=""; NO_CDP=0; PROFILE=""; URL="" +usage() { echo "usage: netvm-chrome.sh [--headless] [--cdp-port N|--no-cdp] [url]"; } +while [ $# -gt 0 ]; do + case "$1" in + --headless) HEADLESS=1; shift;; + --cdp-port) CDP_OVERRIDE="$2"; shift 2;; + --cdp-port=*) CDP_OVERRIDE="${1#*=}"; shift;; + --no-cdp) NO_CDP=1; shift;; + -h|--help) usage; exit 0;; + *) if [ -z "$PROFILE" ]; then PROFILE="$1"; elif [ -z "$URL" ]; then URL="$1"; + else echo "unexpected: $1"; usage; exit 1; fi; shift;; + esac +done +[ -n "$PROFILE" ] || { usage; exit 1; } +NODE="$PROFILE" +netvm_names "$NODE" CHROME_BOX="${CHROME_BOX_BIN:-$HOME/Projects/chrome-box/chrome-box}" [ -x "$CHROME_BOX" ] || { echo "chrome-box not found at $CHROME_BOX (set CHROME_BOX_BIN)"; exit 1; } [ -f "/etc/netvm/${NODE}.conf" ] || { echo "no warp identity for '$NODE' — human: netvm-new-identity.sh $NODE"; exit 1; } -sudo -n "$NETVM_BIN/netvm-node-up.sh" "$NODE" | tail -2 -if [ -n "$URL" ]; then - exec sudo -n "$NETVM_BIN/netvm-enter.sh" "$NODE" "$(id -u)" "$(id -g)" "$HOME" -- "$CHROME_BOX" launch "$PROFILE" "$URL" -else - exec sudo -n "$NETVM_BIN/netvm-enter.sh" "$NODE" "$(id -u)" "$(id -g)" "$HOME" -- "$CHROME_BOX" launch "$PROFILE" -fi + +if [ "$NO_CDP" = 1 ]; then CDP=""; elif [ -n "$CDP_OVERRIDE" ]; then CDP="$CDP_OVERRIDE"; else CDP="$CDP_PORT"; fi + +sudo -n "$NETVM_BIN/netvm-node-up.sh" "$NODE" | tail -1 + +LAUNCH_ARGS=(launch "$PROFILE") +[ "$HEADLESS" = 1 ] && LAUNCH_ARGS+=(--no-sandbox --headless) +[ -n "$CDP" ] && LAUNCH_ARGS+=(--cdp-port "$CDP") +[ -n "$URL" ] && LAUNCH_ARGS+=("$URL") +[ -n "$CDP" ] && echo "cdp: http://$PEER_IP:$CDP/json/list (local) | ssh -L $CDP:$PEER_IP:$CDP @ (remote)" +exec sudo -n "$NETVM_BIN/netvm-enter.sh" "$NODE" "$(id -u)" "$(id -g)" "$HOME" -- "$CHROME_BOX" "${LAUNCH_ARGS[@]}" diff --git a/bin/netvm-names.sh b/bin/netvm-names.sh index ceb1652..0886381 100755 --- a/bin/netvm-names.sh +++ b/bin/netvm-names.sh @@ -9,5 +9,6 @@ netvm_names() { VETH="ve-${_tag}" VPEER="vp-${_tag}" _idx=$(( 0x${_tag:0:3} % 200 + 10 )) + CDP_PORT=$(( 9222 + 0x${_tag:4:3} % 2000 )) GW="10.201.${_idx}.1"; PEER_IP="10.201.${_idx}.2"; SUB="10.201.${_idx}.0/30" }