#!/bin/bash
# Starts Google Chrome in headless mode with remote debugging enabled.
# Usage: ./start-chrome-debug.sh

PORT=9222
USER_DATA_DIR="/tmp/chrome-debug-profile"

echo "Starting Chrome Headless with Remote Debugging on port $PORT..."
echo "User Data Directory: $USER_DATA_DIR"

# Ensure clean state if needed (optional)
# rm -rf $USER_DATA_DIR

google-chrome \
  --headless=new \
  --remote-debugging-port=$PORT \
  --remote-allow-origins=* \
  --user-data-dir=$USER_DATA_DIR \
  --disable-gpu \
  --no-sandbox \
  --disable-dev-shm-usage \
  --ignore-certificate-errors \
  "https://localhost:3456" &

CHROME_PID=$!
echo "Chrome started with PID $CHROME_PID"
echo "To connect via SSH tunnel from your local machine:"
echo "ssh -L 9222:localhost:9222 user@your-server-ip"
echo "Then open chrome://inspect in your local browser."
