#!/usr/bin/env bash # 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 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; } # Visible launch needs a display. Auto-detect Wayland when the shell # doesn't have one (e.g. ssh/bare terminal on a Wayland desktop). if [ -z "${WAYLAND_DISPLAY:-}" ] && [ -z "${DISPLAY:-}" ]; then for _s in "/run/user/$(id -u)"/wayland-*; do case "$_s" in *.lock|*'\*') continue;; esac [ -S "$_s" ] || continue export WAYLAND_DISPLAY="$(basename "$_s")" [ -z "${XDG_RUNTIME_DIR:-}" ] && export XDG_RUNTIME_DIR="/run/user/$(id -u)" echo "display: auto-detected WAYLAND_DISPLAY=$WAYLAND_DISPLAY" >&2 break done fi 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; } 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[@]}"