#!/bin/bash
exec > /tmp/amdwork/relaunch_nopopup.out 2>&1
export DISPLAY=:99
# Kill ONLY the agent-profile chrome (port 9223 / chrome-profile-agent). Do NOT touch 9222 main.
pkill -f "chrome-profile-agent" || echo "no agent chrome to kill"
sleep 3
nohup /usr/bin/google-chrome \
  --user-data-dir=/home/claude/chrome-profile-agent \
  --remote-debugging-port=9223 \
  --remote-debugging-address=127.0.0.1 \
  --remote-allow-origins=* \
  --no-first-run \
  --no-default-browser-check \
  --disable-popup-blocking \
  --disable-gpu-compositing \
  --ozone-platform=x11 \
  --window-position=0,0 \
  --window-size=1440,900 \
  --lang=en-US \
  about:blank \
  > /tmp/amdwork/chrome-agent.log 2>&1 &
echo "relaunched pid=$!"
sleep 7
echo "=== CDP version ==="
curl -s http://localhost:9223/json/version || echo "9223 NOT UP"
echo ""
echo "=== verify 9222 main still up ==="
curl -s http://localhost:9222/json/version | head -c 120 || echo "9222 not reachable (may be fine)"
echo ""
echo "=== DONE RELAUNCH ==="
