#!/bin/bash
# 用法: ./run_once.sh N TAG [dsf]  —— 重启 chrome + 跑 repro.py + 清理
set -x
pkill -f "chrome[-]linux64/chrome" 2>/dev/null
sleep 1
CHROME=/home/user/.cache/ms-playwright/chromium-1243/chrome-linux64/chrome
nohup $CHROME --headless=new --no-sandbox --disable-gpu --disable-dev-shm-usage \
  --remote-debugging-port=9222 --user-data-dir=/tmp/cdp --memory-allocator=tcmalloc about:blank \
  >/tmp/chrome.log 2>&1 &
for i in $(seq 1 20); do curl -s http://localhost:9222/json/version >/dev/null && break; sleep 1; done
cd /home/user/shots
timeout 120 python3 repro.py "$1" "$2" "${3:-3}" > "run_$2.log" 2>&1
RC=$?
pkill -f "chrome[-]linux64/chrome" 2>/dev/null
echo "RC=$RC"
tail -3 "run_$2.log"
exit $RC
