42 lines
1.4 KiB
PowerShell
42 lines
1.4 KiB
PowerShell
# PowerShell脚本:启动Chrome浏览器并启用远程调试
|
||
|
||
# Chrome浏览器路径
|
||
$chromePath = "C:\Program Files\Google\Chrome\Application\chrome.exe"
|
||
|
||
# 检查Chrome是否已安装
|
||
if (-not (Test-Path $chromePath)) {
|
||
Write-Host "错误:Chrome浏览器未找到,请检查安装路径" -ForegroundColor Red
|
||
exit 1
|
||
}
|
||
|
||
# 用户数据目录
|
||
$userDataDir = "C:\temp\chrome_debug"
|
||
|
||
# 创建用户数据目录(如果不存在)
|
||
if (-not (Test-Path $userDataDir)) {
|
||
New-Item -ItemType Directory -Path $userDataDir -Force | Out-Null
|
||
Write-Host "已创建用户数据目录: $userDataDir" -ForegroundColor Green
|
||
}
|
||
|
||
# 启动Chrome浏览器
|
||
$arguments = @(
|
||
"--remote-debugging-port=9222",
|
||
"--start-maximized",
|
||
"--user-data-dir=`"$userDataDir`""
|
||
)
|
||
|
||
Write-Host "正在启动Chrome浏览器..." -ForegroundColor Yellow
|
||
Write-Host "命令: $chromePath $arguments" -ForegroundColor Cyan
|
||
|
||
# 启动Chrome进程
|
||
$process = Start-Process -FilePath $chromePath -ArgumentList $arguments -PassThru
|
||
|
||
if ($process) {
|
||
Write-Host "Chrome浏览器已启动,进程ID: $($process.Id)" -ForegroundColor Green
|
||
Write-Host "远程调试端口: 9222" -ForegroundColor Green
|
||
Write-Host "用户数据目录: $userDataDir" -ForegroundColor Green
|
||
Write-Host ""
|
||
Write-Host "现在可以运行Playwright脚本来连接此Chrome实例" -ForegroundColor Yellow
|
||
} else {
|
||
Write-Host "启动Chrome浏览器失败" -ForegroundColor Red
|
||
} |