Installing Chrome browser on an Agent
Hello there,
I'm trying to run my unit tests with Chrome headless and I need to the install Google Chrome on an Azure agent. I'm wondering how can I do that. I tried a few founds over the net:
also with:
steps:
# Install Google Chrome on the virtual machine
- powershell: |
$chromeInstaller = "chrome_installer.exe"
Invoke-WebRequest -Uri "https://dl.google.com/chrome/install/latest/chrome_installer.exe" -OutFile $chromeInstaller
Start-Process -FilePath $chromeInstaller -ArgumentList "/silent", "/install" -NoNewWindow -Wait
Remove-Item -Path $chromeInstaller
displayName: 'Install Google Chrome'
and also with chocolatey, but I'm constantly getting errors.
My question is:
is there a convinient way to install google chrome browser before other dependencies of my project?
Azure Virtual Machines
-
Vladimir Varbanov • 0 Reputation points
2025-02-24T13:07:03.06+00:00 Also, this is a Windows machine.
-
Geethasri.V • 0 Reputation points • Microsoft External Staff
2025-02-24T17:19:46.9233333+00:00 Thank you for reaching out to the Microsoft Q&A Platform!
It seems like you are looking for a way to install Google Chrome browser on an Azure agent to run your unit tests with Chrome headless.
There are a few methods you can try to install Google Chrome on an Azure agent.
One common way to install Google Chrome on a Windows machine is by downloading the Chrome installer executable and running it silently.
Here is an example PowerShell script that you can use in your Azure Pipeline to install Google Chrome:
powershell $chromeInstaller = "chrome_installer.exe" Invoke-WebRequest -Uri https://dl.google.com/chrome/install/latest/chrome_installer.exe -OutFile $chromeInstaller Start-Process -FilePath $chromeInstaller -ArgumentList "/silent", "/install" -NoNewWindow -Wait Remove-Item -Path $chromeInstaller
You can include this script as a step in your Azure Pipeline to install Google Chrome before running your unit tests.
Another approach you mentioned is using Chocolatey. Chocolatey is a package manager for Windows that can simplify the installation of software packages. If you are encountering errors with Chocolatey, you may need to troubleshoot the specific issues you are facing.
If you continue to face challenges with installing Google Chrome using the methods you mentioned, you can also explore other options such as using a custom script or a different package manager.
I hope this helps you install Google Chrome on your Azure agent for running your unit tests.
If the information is helpful, please consider by clicking the "Upvote".
If you have any further queries, please let us know we are glad to help you.
Thank you.
-
Vladimir Varbanov • 0 Reputation points
2025-02-25T10:12:54.9133333+00:00 Hi there,
I have the folloing error after including this powershell script:
Starting: PowerShell ============================================================================== Task : PowerShell Description : Run a PowerShell script on Linux, macOS, or Windows Version : 2.228.1 Author : Microsoft Corporation Help : https://docs.microsoft.com/azure/devops/pipelines/tasks/utility/powershell ============================================================================== Generating script. ========================== Starting Command Output =========================== "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command ". 'D:\build-agent1\_work\_temp\8846b2f1-de82-4ecf-84e7-d2c315ac9e4d.ps1'" At D:\build-agent1\_work\_temp\8846b2f1-de82-4ecf-84e7-d2c315ac9e4d.ps1:4 char:44 + $chromeInstaller = "chrome_installer.exe" Invoke-WebRequest -Uri htt ... + ~~~~~~~~~~~~~~~~~ Unexpected token 'Invoke-WebRequest' in expression or statement. + CategoryInfo : ParserError: (:) [], ParseException + FullyQualifiedErrorId : UnexpectedToken ##[error]PowerShell exited with code '1'. Finishing: PowerShell
I have this step in my YAML file:
steps: - powershell: $chromeInstaller = "chrome_installer.exe" Invoke-WebRequest -Uri https://dl.google.com/chrome/install/latest/chrome_installer.exe -OutFile $chromeInstaller Start-Process -FilePath $chromeInstaller -ArgumentList "/silent", "/install" -NoNewWindow -Wait Remove-Item -Path $chromeInstaller
I also tried
- task: PowerShell@2 inputs: targetType: 'inline' script: powershell $chromeInstaller = "chrome_installer.exe" Invoke-WebRequest -Uri https://dl.google.com/chrome/install/latest/chrome_installer.exe -OutFile $chromeInstaller Start-Process -FilePath $chromeInstaller -ArgumentList "/silent", "/install" -NoNewWindow -Wait Remove-Item -Path $chromeInstaller ====Error is Starting: PowerShell ============================================================================== Task : PowerShell Description : Run a PowerShell script on Linux, macOS, or Windows Version : 2.228.1 Author : Microsoft Corporation Help : https://docs.microsoft.com/azure/devops/pipelines/tasks/utility/powershell ============================================================================== Generating script. ========================== Starting Command Output =========================== "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command ". 'D:\build-agent1\_work\_temp\0a5fcf5c-a5ea-4be8-8a72-18b07e1265fc.ps1'" = : The term '=' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spell ing of the name, or if a path was included, verify that the path is correct and try again. At line:1 char:1 + = chrome_installer.exe Invoke-WebRequest -Uri https://dl.google.com/c ... + ~ + CategoryInfo : ObjectNotFound: (=:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException ##[error]PowerShell exited with code '1'. Finishing: PowerShell
-
Geethasri.V • 0 Reputation points • Microsoft External Staff
2025-02-26T06:18:15.55+00:00 Hi Vladimir Varbanov,
The errors are caused by incorrect syntax in the way the PowerShell script is being executed in your YAML file.Specifically, you're missing some important delimiters like the
|
for multiline scripts and a few other minor issues.steps: - task: PowerShell@2 inputs: targetType: 'inline' script: | $chromeInstaller="chrome_installer.exe"; Invoke-WebRequest -Uri "https://dl.google.com/chrome/install/latest/chrome_installer.exe" -OutFile $chromeInstaller; Start-Process -FilePath $chromeInstaller -ArgumentList "/silent", "/install" -NoNewWindow -Wait; Remove-Item -Path $chromeInstaller displayName: 'Install Google Chrome'
This should resolve the syntax issue and install Chrome successfully on the agent.
If the information is helpful, please consider by clicking the "Upvote".
If you have any further queries, please let us know we are glad to help you.
Thank you.
-
Vladimir Varbanov • 0 Reputation points
2025-02-26T10:23:16.25+00:00 Hi there,
thank you for the answer.
I though have the following error again using the script above:
Starting: PowerShell ============================================================================== Task : PowerShell Description : Run a PowerShell script on Linux, macOS, or Windows Version : 2.228.1 Author : Microsoft Corporation Help : ============================================================================== Generating script. ========================== Starting Command Output =========================== "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command ". 'D:\build-agent1\_work\_temp\906bfd37-f314-44dd-b2fc-0bfe702c4842.ps1'" Invoke-WebRequest : The underlying connection was closed: An unexpected error occurred on a send. At D:\build-agent1\_work\_temp\906bfd37-f314-44dd-b2fc-0bfe702c4842.ps1:4 char:42 + ... aller.exe"; Invoke-WebRequest -Uri " + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebExc eption + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand ##[error]PowerShell exited with code '1'. Finishing: PowerShell
I put the following line:
steps: - task: PowerShell@2 inputs: targetType: 'inline' script: | $chromeInstaller="chrome_installer.exe"; Invoke-WebRequest -Uri "https://dl.google.com/chrome/install/latest/chrome_installer.exe" -OutFile $chromeInstaller; Start-Process -FilePath $chromeInstaller -ArgumentList "/silent", "/install" -NoNewWindow -Wait; Remove-Item -Path $chromeInstaller displayName: 'Install Google Chrome'
-
Geethasri.V • 0 Reputation points • Microsoft External Staff
2025-02-26T19:43:04.87+00:00 Below is a corrected and simplified PowerShell script to install Google Chrome on an Azure agent using PowerShell.
This version fixes the issues you encountered and adds error handling.
steps: - task: PowerShell@2 inputs: targetType: 'inline' script: | # Ensure TLS 1.2 for secure connection[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 # Define installer and download URL $chromeInstaller = "chrome_installer.exe" $chromeInstallerUrl = "https://dl.google.com/chrome/install/latest/chrome_installer.exe" try { # Download Chrome installer Invoke-WebRequest -Uri $chromeInstallerUrl -OutFile $chromeInstaller } catch { Write-Host "Failed to download Chrome installer: $_" exit 1 } try { # Install Google Chrome Start-Process -FilePath $chromeInstaller -ArgumentList "/silent", "/install" -NoNewWindow -Wait } catch { Write-Host "Failed to install Chrome: $_" exit 1 } # Clean up the installer Remove-Item -Path $chromeInstaller -Force displayName: 'Install Google Chrome'
If the information is helpful, please consider by clicking the "Upvote".
If you have any further queries, please let us know we are glad to help you.
Thank you.
-
Vladimir Varbanov • 0 Reputation points
2025-03-02T18:22:25.4333333+00:00 Thank you for your persistent support and for following up on my issue. Unfortunately, I have an error again. I know this is getting too much, but I didn't know that installing something on a DevOps Agent could be that complicated.
Starting: PowerShell ============================================================================== Task : PowerShell Description : Run a PowerShell script on Linux, macOS, or Windows Version : 2.228.1 Author : Microsoft Corporation Help : ============================================================================== Generating script. ========================== Starting Command Output =========================== "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command ". 'D:\build-agent1\_work\_temp\6ed7c103-8e1a-4073-afd2-eb0fd78a702d.ps1'" Failed to download Chrome installer: The underlying connection was closed: An unexpected error occurred on a send. ##[error]PowerShell exited with code '1'. Finishing: PowerShell
Sign in to comment