@echo off
REM ============================================================
REM Edge Launcher for Windows
REM Purpose: Launch Edge/Chrome browser with security disabled
REM Warning: Do NOT use for production or sensitive websites!
REM ============================================================

REM === Edge path detection (32/64 bit compatible) ===
set "EDGE_PATH=C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe"
if not exist "%EDGE_PATH%" (
    set "EDGE_PATH=C:\Program Files\Microsoft\Edge\Application\msedge.exe"
)

REM === Chrome as fallback ===
set "CHROME_PATH=C:\Program Files\Google\Chrome\Application\chrome.exe"
if not exist "%CHROME_PATH%" (
    set "CHROME_PATH=C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"
)

REM === Create user profile directory ===
set "USER_DIR=%USERPROFILE%\edge_profile"
if not exist "%USER_DIR%" (
    mkdir "%USER_DIR%"
    echo Created profile directory: %USER_DIR%
)

REM === Select browser ===
set "BROWSER_PATH="
set "BROWSER_NAME="

if exist "%EDGE_PATH%" (
    set "BROWSER_PATH=%EDGE_PATH%"
    set "BROWSER_NAME=Microsoft Edge"
) else if exist "%CHROME_PATH%" (
    set "BROWSER_PATH=%CHROME_PATH%"
    set "BROWSER_NAME=Google Chrome"
) else (
    echo [ERROR] Edge or Chrome browser not found!
    pause
    exit /b 1
)

echo ============================================================
echo Launching browser: %BROWSER_NAME%
echo Profile directory: %USER_DIR%
echo ============================================================
echo.

REM === Launch browser ===
start "" "%BROWSER_PATH%" --disable-web-security --user-data-dir="%USER_DIR%" --allow-insecure-localhost --ignore-certificate-errors --disable-features=IsolateOrigins,site-per-process

echo Browser launched!

REM === Create desktop shortcut ===
echo.
echo Creating desktop shortcut...

powershell -NoProfile -ExecutionPolicy Bypass -Command "$WS = New-Object -ComObject WScript.Shell; $SC = $WS.CreateShortcut([Environment]::GetFolderPath('Desktop') + '\%BROWSER_NAME% Safe.lnk'); $SC.TargetPath = '%BROWSER_PATH%'; $SC.Arguments = '--disable-web-security --user-data-dir=\"%USERPROFILE%\edge_profile\" --allow-insecure-localhost --ignore-certificate-errors --disable-features=IsolateOrigins,site-per-process'; $SC.WorkingDirectory = '%USERPROFILE%'; $SC.Description = '%BROWSER_NAME% Safe Mode'; $SC.IconLocation = '%BROWSER_PATH%,0'; $SC.Save(); Write-Host '[OK] Desktop shortcut created' -ForegroundColor Green"

if %ERRORLEVEL% equ 0 (
    echo.
    echo ============================================================
    echo [SUCCESS] Desktop shortcut created!
    echo Location: %USERPROFILE%\Desktop\%BROWSER_NAME% Safe.lnk
    echo ============================================================
) else (
    echo [WARNING] Shortcut creation failed, please create manually
)

echo.
echo Press any key to exit...
pause >nul
exit /b 0