azure-dev
azure-dev copied to clipboard
Launch the browser using environment variable $BROWSER (if present)
Launching the browser in Codespaces is best accomplished using the command at the $BROWSER environment variable. This adds logic to launch the browser using $BROWSER if executing in codespaces that environment variable is set.
How gh CLI does it:
The gh CLI resolves a browser by checking for GH_BROWSER (not set in codespaces), gh-specific configuration, and finally BROWSER. Since BROWSER is set the gh CLI can launch the browser.
I'd like to have used this module in our code but it's coupled to config which github recommends against using in non-gh CLI projects.
How az CLI does it:
From some digging in the az CLI codebase, I strongly believe that the az CLI calls methods in msal which itself uses the built-in webbrowser module. The built-in module has more behavior around parsing the value of $BROWSER but the effect is the same in the Codespaces instance.
What's happening in Codespaces?
The BROWSER environment variable has a value like:
/vscode/bin/linux-x64/<string-of-characters>/bin/helpers/browser.sh
And that script currently is of the form:
#!/usr/bin/env sh
#
# Copyright (c) Microsoft Corporation. All rights reserved.
#
ROOT="$(dirname "$(dirname "$(dirname "$(readlink -f "$0")")")")"
APP_NAME="code"
VERSION="1.72.3"
COMMIT="f69482e92e41b84fb15688f3c0d0a1eca1d5bce3"
EXEC_NAME="code"
CLI_SCRIPT="$ROOT/out/server-cli.js"
"$ROOT/node" "$CLI_SCRIPT" "$APP_NAME" "$VERSION" "$COMMIT" "$EXEC_NAME" "--openExternal" "$@"
The server-cli.js itself is minified and difficult to read.
Fixes https://github.com/Azure/azure-dev/issues/935
Related: https://github.com/Azure/azure-dev/issues/394
How to test:
In codepsaces
- Launch a codespaces instance against a sample repo (e.g. https://github.com/azure-samples/todo-nodejs-mongo)
- Upgrade the
azdclient to the current PR (in the console):
curl -fsSL https://azuresdkreleasepreview.blob.core.windows.net/azd/standalone/pr/934/install-azd.sh | bash -s -- --base-url https://azuresdkreleasepreview.blob.core.windows.net/azd/standalone/pr/934 --version '' --verbose
- In the console (or using the extension) run
azd upandazd monitor(follow prompts as needed) - Run
azd down --force --purgeto clean up test environment - Dispose of the codespaces instance
Browser launch successful:

Locally
Places where this does not work: ~WSL (not a regression at this point, latest is already not working for this scenario)~ works in WSL now
- Install
azdusing instructions form the PR comment up above - Init a sample app (e.g.
azd init -t Azure-Samples/todo-nodejs-mongo) - Run
azd upandazd monitor(follow prompts as needed) - Run
azd down --force --purgeto clean up test environment
@vhvb1989 -- Can you try this out in your vm running vscode server? If the $BROWSER environment variable is set I suspect it'll probably work.
Azure Dev CLI Install Instructions
Install scripts
MacOS/Linux
May elevate using
sudoon some platforms and configurations
bash:
curl -fsSL https://azuresdkreleasepreview.blob.core.windows.net/azd/standalone/pr/934/uninstall-azd.sh | bash;
curl -fsSL https://azuresdkreleasepreview.blob.core.windows.net/azd/standalone/pr/934/install-azd.sh | bash -s -- --base-url https://azuresdkreleasepreview.blob.core.windows.net/azd/standalone/pr/934 --version '' --verbose
pwsh:
Invoke-RestMethod 'https://azuresdkreleasepreview.blob.core.windows.net/azd/standalone/pr/934/uninstall-azd.ps1' -OutFile uninstall-azd.ps1; ./uninstall-azd.ps1
Invoke-RestMethod 'https://azuresdkreleasepreview.blob.core.windows.net/azd/standalone/pr/934/install-azd.ps1' -OutFile install-azd.ps1; ./install-azd.ps1 -BaseUrl 'https://azuresdkreleasepreview.blob.core.windows.net/azd/standalone/pr/934' -Version '' -Verbose
Windows
powershell -c "Set-ExecutionPolicy Bypass Process; irm 'https://azuresdkreleasepreview.blob.core.windows.net/azd/standalone/pr/934/uninstall-azd.ps1' > uninstall-azd.ps1; ./uninstall-azd.ps1;"
powershell -c "Set-ExecutionPolicy Bypass Process; irm 'https://azuresdkreleasepreview.blob.core.windows.net/azd/standalone/pr/934/install-azd.ps1' > install-azd.ps1; ./install-azd.ps1 -BaseUrl 'https://azuresdkreleasepreview.blob.core.windows.net/azd/standalone/pr/934' -Version '' -Verbose;"
Standalone Binary
- Linux - https://azuresdkreleasepreview.blob.core.windows.net/azd/standalone/pr/934/azd-linux-amd64.tar.gz
- MacOS - https://azuresdkreleasepreview.blob.core.windows.net/azd/standalone/pr/934/azd-darwin-amd64.zip
- Windows - https://azuresdkreleasepreview.blob.core.windows.net/azd/standalone/pr/934/azd-windows-amd64.zip
Container
docker run -it azdevcliextacr.azurecr.io/azure-dev:pr-934