[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
$ErrorActionPreference = 'Continue'

$userDataDir = "C:\ChromeDebug_BJH"
$chrome = "C:\Program Files\Google\Chrome\Application\chrome.exe"

$argList = @(
    "--remote-debugging-port=9223",
    "--user-data-dir=$userDataDir",
    "--no-first-run",
    "--no-default-browser-check",
    "--disable-crash-reporter",
    "--noerrdialogs",
    "--incognito",
    "https://baijiahao.baidu.com"
)

Write-Host "Launching Chrome (incognito)..."
$proc = Start-Process -FilePath $chrome -ArgumentList $argList -PassThru
Write-Host "PID: $($proc.Id)"
Start-Sleep 8

$check = Get-Process -Id $proc.Id -ErrorAction SilentlyContinue
if ($check) {
    Write-Host "[OK] Chrome running - Window: $($check.MainWindowTitle)"
} else {
    Write-Host "[FAIL] ExitCode: $($proc.ExitCode)"
}
