azure-dev icon indicating copy to clipboard operation
azure-dev copied to clipboard

Launch the browser using environment variable $BROWSER (if present)

Open danieljurek opened this issue 3 years ago • 4 comments

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.

danieljurek avatar Oct 20 '22 13:10 danieljurek

Fixes https://github.com/Azure/azure-dev/issues/935

Related: https://github.com/Azure/azure-dev/issues/394

danieljurek avatar Oct 20 '22 13:10 danieljurek

How to test:

In codepsaces

  1. Launch a codespaces instance against a sample repo (e.g. https://github.com/azure-samples/todo-nodejs-mongo)
  2. Upgrade the azd client 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
  1. In the console (or using the extension) run azd up and azd monitor (follow prompts as needed)
  2. Run azd down --force --purge to clean up test environment
  3. Dispose of the codespaces instance

Browser launch successful:

image

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

  1. Install azd using instructions form the PR comment up above
  2. Init a sample app (e.g. azd init -t Azure-Samples/todo-nodejs-mongo)
  3. Run azd up and azd monitor (follow prompts as needed)
  4. Run azd down --force --purge to clean up test environment

danieljurek avatar Oct 20 '22 14:10 danieljurek

@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.

danieljurek avatar Oct 20 '22 16:10 danieljurek

Azure Dev CLI Install Instructions

Install scripts

MacOS/Linux

May elevate using sudo on 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

azure-sdk avatar Oct 20 '22 22:10 azure-sdk