Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 38 additions & 1 deletion src/playwright/install.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,40 @@
#!/bin/bash

npx playwright install --with-deps ${BROWSERS}
set -e

# Determine the appropriate non-root user
USERNAME="${USERNAME:-"${_REMOTE_USER:-"automatic"}"}"

if [ "${USERNAME}" = "auto" ] || [ "${USERNAME}" = "automatic" ]; then
if [ -n "${_REMOTE_USER}" ] && [ "${_REMOTE_USER}" != "root" ]; then
USERNAME="${_REMOTE_USER}"
else
USERNAME=""
POSSIBLE_USERS=("vscode" "node" "codespace" "$(awk -v val=1000 -F ":" '$3==val{print $1}' /etc/passwd)")
Comment thread
schlich marked this conversation as resolved.
Resolved
for CURRENT_USER in "${POSSIBLE_USERS[@]}"; do
if [ -n "${CURRENT_USER}" ] && id -u ${CURRENT_USER} > /dev/null 2>&1; then
USERNAME=${CURRENT_USER}
break
fi
done
if [ "${USERNAME}" = "" ]; then
USERNAME=root
fi
fi
elif [ "${USERNAME}" = "none" ]; then
USERNAME=root
fi

# Verify the user exists, if not, fall back to root
if [ "${USERNAME}" != "root" ] && ! id -u ${USERNAME} > /dev/null 2>&1; then
echo "Warning: User ${USERNAME} does not exist, falling back to root."
USERNAME=root
fi

# Install Playwright browsers as the determined user
if [ "${USERNAME}" = "root" ]; then
npx playwright install --with-deps ${BROWSERS}
else
# Preserve PATH and NODE environment when switching users
su ${USERNAME} -c "PATH=\"${PATH}\" npx playwright install --with-deps ${BROWSERS}"
Comment thread
schlich marked this conversation as resolved.
Resolved
fi
8 changes: 8 additions & 0 deletions test/playwright/scenarios.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,13 @@
"browsers": "firefox chromium"
}
}
},
"test_user_install": {
"image": "ubuntu:focal",
"features": {
"playwright": {
"browsers": "chromium"
}
}
}
}
16 changes: 16 additions & 0 deletions test/playwright/test_user_install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash

set -e

source dev-container-features-test-lib

# Test that Playwright installs correctly
check "Playwright is available" npx playwright --version

# Check that we can list browsers (this means the installation worked)
check "Can list browsers" npx playwright install --list

# Verify the feature works with basic commands
check "Basic playwright functionality" bash -c 'npx playwright --help | grep -q "Usage"'

reportResults