lib/.playwright/package/bin/reinstall_chrome_beta_win.ps1

$ErrorActionPreference = 'Stop'

$url = 'https://dl.google.com/tag/s/dl/chrome/install/beta/googlechromebetastandaloneenterprise64.msi'

Microsoft.PowerShell.Utility\Write-Host "Downloading Google Chrome Beta"
$wc = Microsoft.PowerShell.Utility\New-Object net.webclient
$msiInstaller = "$env:temp\google-chrome-beta.msi"
$wc.Downloadfile($url, $msiInstaller)

Microsoft.PowerShell.Utility\Write-Host "Installing Google Chrome Beta"
$arguments = "/i `"$msiInstaller`" /quiet"
Microsoft.PowerShell.Management\Start-Process msiexec.exe -ArgumentList $arguments -Wait
Microsoft.PowerShell.Management\Remove-Item $msiInstaller

$suffix = "\\Google\\Chrome Beta\\Application\\chrome.exe"
if (Microsoft.PowerShell.Management\Test-Path "${env:ProgramFiles(x86)}$suffix") {
    (Microsoft.PowerShell.Management\Get-Item "${env:ProgramFiles(x86)}$suffix").VersionInfo
} elseif (Microsoft.PowerShell.Management\Test-Path "${env:ProgramFiles}$suffix") {
    (Microsoft.PowerShell.Management\Get-Item "${env:ProgramFiles}$suffix").VersionInfo
} else {
    Microsoft.PowerShell.Utility\Write-Host "ERROR: Failed to install Google Chrome Beta."
    Microsoft.PowerShell.Utility\Write-Host "ERROR: This could be due to insufficient privileges, in which case re-running as Administrator may help."
    exit 1
}