$ErrorActionPreference = 'Continue'
$chrome = "C:\Program Files\Google\Chrome\Application\chrome.exe"
$argList = "--remote-debugging-port=9223 --user-data-dir=C:\ChromeDebug_BJH --no-first-run --no-default-browser-check https://baijiahao.baidu.com"
Write-Host "Chrome path: $chrome"
Write-Host "Args: $argList"
Write-Host "Chrome exists: $(Test-Path $chrome)"

$pinfo = New-Object System.Diagnostics.ProcessStartInfo
$pinfo.FileName = $chrome
$pinfo.Arguments = $argList
$pinfo.UseShellExecute = $false
$pinfo.RedirectStandardOutput = $true
$pinfo.RedirectStandardError = $true
$pinfo.CreateNoWindow = $false

$p = New-Object System.Diagnostics.Process
$p.StartInfo = $pinfo
$p.Start() | Out-Null

Write-Host "PID: $($p.Id)"
Start-Sleep 5

$chromeProc = Get-Process -Id $p.Id -ErrorAction SilentlyContinue
if ($chromeProc) {
    Write-Host "Chrome is running - MainWindowTitle: $($chromeProc.MainWindowTitle)"
} else {
    Write-Host "Chrome process not found"
    Write-Host "Stderr: $($p.StandardError.ReadToEnd())"
}
