From 55bc36a85b9e3839e1ddc9d2dc56ef0f8ac9114e Mon Sep 17 00:00:00 2001 From: Eric Lavigne Date: Mon, 27 Oct 2025 10:07:52 -0600 Subject: [PATCH] SERVER-112612: Add xdg-open wrapper to open browser urls on the host (#43174) GitOrigin-RevId: 277d7824e33d5e863beafa339fdcfa723a119794 --- .devcontainer/Dockerfile | 10 +++++++++- .devcontainer/xdg-open-wrapper.sh | 20 ++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100755 .devcontainer/xdg-open-wrapper.sh diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 3e07adbcc09..2505fd9c161 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -10,7 +10,15 @@ ARG USER_GID=$USER_UID # Create the user RUN groupadd $USERNAME && useradd -s /bin/bash --gid $USER_GID -m $USERNAME -RUN apt-get update && apt-get install -y sudo curl ca-certificates +RUN apt-get update && apt-get install -y sudo curl ca-certificates xdg-utils + +# Install xdg-open wrapper for browser integration +COPY .devcontainer/xdg-open-wrapper.sh /usr/local/bin/xdg-open-wrapper.sh +RUN chmod +x /usr/local/bin/xdg-open-wrapper.sh && \ + if [ -f /usr/bin/xdg-open ]; then \ + mv /usr/bin/xdg-open /usr/bin/xdg-open.real; \ + fi && \ + ln -s /usr/local/bin/xdg-open-wrapper.sh /usr/bin/xdg-open # Give user sudo access RUN echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/devcontaineruser && chmod 0440 /etc/sudoers.d/devcontaineruser diff --git a/.devcontainer/xdg-open-wrapper.sh b/.devcontainer/xdg-open-wrapper.sh new file mode 100755 index 00000000000..6a5309759b2 --- /dev/null +++ b/.devcontainer/xdg-open-wrapper.sh @@ -0,0 +1,20 @@ +#!/bin/bash +# xdg-open wrapper for devcontainer +# Launches URLs using VSCode's $BROWSER environment variable +# Falls back to native xdg-open for non-URLs + +NATIVE_XDG_OPEN="/usr/bin/xdg-open.real" + +# If it's an HTTP/HTTPS URL and $BROWSER is set, use it +if [[ "$1" == http:* || "$1" == https:* ]] && [ -n "$BROWSER" ]; then + exec "$BROWSER" "$@" +fi + +# Otherwise, fall back to native xdg-open if it exists +if [ -x "$NATIVE_XDG_OPEN" ]; then + exec "$NATIVE_XDG_OPEN" "$@" +fi + +# If we get here, we couldn't handle it +echo "Error: Cannot open '$1' - no suitable handler found" >&2 +exit 1