@echo off
REM Launches a separate Brave instance with remote debugging enabled, so the
REM PSA comp helper can attach via CDP. This Brave window uses its OWN profile
REM (independent of your normal Brave) — log in to Cardladder once in this
REM window and the cookies stick around for future sessions.
REM
REM Brave is preferred over Chrome because Cardladder's reCAPTCHA scores
REM fresh-profile Chrome as a bot and silently rejects login. Brave's
REM fingerprint scores higher and gets through.
REM
REM Run this every time before starting the helper. Keep the window open while
REM the helper runs.

setlocal
set "PROFILE=%~dp0brave-profile"
if not exist "%PROFILE%" mkdir "%PROFILE%"

set "BRAVE="
if exist "%ProgramFiles%\BraveSoftware\Brave-Browser\Application\brave.exe" set "BRAVE=%ProgramFiles%\BraveSoftware\Brave-Browser\Application\brave.exe"
if not defined BRAVE if exist "%ProgramFiles(x86)%\BraveSoftware\Brave-Browser\Application\brave.exe" set "BRAVE=%ProgramFiles(x86)%\BraveSoftware\Brave-Browser\Application\brave.exe"
if not defined BRAVE if exist "%LocalAppData%\BraveSoftware\Brave-Browser\Application\brave.exe" set "BRAVE=%LocalAppData%\BraveSoftware\Brave-Browser\Application\brave.exe"

if not defined BRAVE (
  echo Could not find brave.exe in standard install locations.
  echo Install Brave from https://brave.com and try again.
  pause
  exit /b 1
)

echo Launching Brave with remote debugging on port 9222...
echo Profile: %PROFILE%
echo.
echo Leave this window open while the helper is running.
echo Log into Cardladder in the Brave window the first time.
echo.

"%BRAVE%" ^
  --remote-debugging-port=9222 ^
  --user-data-dir="%PROFILE%" ^
  --no-default-browser-check ^
  --no-first-run ^
  "https://app.cardladder.com"

endlocal
