$ErrorActionPreference = 'Stop'

$chrome = "C:\Program Files\Google\Chrome\Application\chrome.exe"
$debugPort = "9223"
$userDataDir = "C:\ChromeDebug"
$url = "https://baijiahao.baidu.com/builder/rc/edit?type=news"

$argList = @(
    "--remote-debugging-port=$debugPort",
    "--user-data-dir=$userDataDir",
    "--no-first-run",
    "--no-default-browser-check",
    "--disable-crash-reporter",
    "--noerrdialogs",
    $url
)

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

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