$ErrorActionPreference = 'Continue'

# Create dir with icacls (bypass PowerShell path issues)
$dir = "C:\ChromeDebug_BJH"
$null = [System.IO.Directory]::CreateDirectory($dir)
Write-Host "Dir created/confirmed: $dir"

$chrome = "C:\Program Files\Google\Chrome\Application\chrome.exe"
$argList = "--remote-debugging-port=9223 --user-data-dir=`"$dir`" --no-first-run --no-default-browser-check --disable-crash-reporter `"https://baijiahao.baidu.com/builder/rc/edit?type=news`""

Write-Host "Starting Chrome..."
$proc = Start-Process $chrome -ArgumentList $argList -PassThru -WindowStyle Normal
Write-Host "PID: $($proc.Id)"

Start-Sleep 4

$running = Get-Process -Id $proc.Id -ErrorAction SilentlyContinue
if ($running) {
    Write-Host "SUCCESS - Chrome running. Window title: $($running.MainWindowTitle)"
} else {
    Write-Host "Chrome exited. ExitCode: $($proc.ExitCode)"
}
