Skip to content

Commit 136a2c3

Browse files
authored
Merge pull request #82 from schlich/copilot/fix-5411878d-0653-4b37-9ec3-22f3412632a7
Fix Playwright dev container feature to install browsers under non-root user
2 parents dcb8dc9 + d195d7f commit 136a2c3

3 files changed

Lines changed: 49 additions & 1 deletion

File tree

src/playwright/install.sh

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
11
#!/bin/bash
22

3-
npx playwright install --with-deps ${BROWSERS}
3+
set -e
4+
5+
# Install Playwright browsers
6+
# If _REMOTE_USER is set and not root, install as that user
7+
# Otherwise install as root (test scenarios)
8+
if [ -n "${_REMOTE_USER}" ] && [ "${_REMOTE_USER}" != "root" ] && id -u "${_REMOTE_USER}" > /dev/null 2>&1; then
9+
su "${_REMOTE_USER}" -c "npx playwright install --with-deps ${BROWSERS}"
10+
else
11+
npx playwright install --with-deps ${BROWSERS}
12+
fi

test/playwright/scenarios.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,13 @@
1414
"browsers": "firefox chromium"
1515
}
1616
}
17+
},
18+
"test_user_install": {
19+
"image": "ubuntu:focal",
20+
"features": {
21+
"playwright": {
22+
"browsers": "chromium"
23+
}
24+
}
1725
}
1826
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
source dev-container-features-test-lib
6+
7+
# Test that Playwright is installed
8+
check "Playwright is available" npx playwright --version
9+
10+
# Check that browsers are installed in user's home directory (not root)
11+
CURRENT_USER=$(whoami)
12+
USER_HOME=$(eval echo ~${CURRENT_USER})
13+
14+
# Verify browser cache exists in the user's home directory
15+
check "Browser cache in user home" test -d "${USER_HOME}/.cache/ms-playwright"
16+
17+
# Verify the cache directory is owned by the current user
18+
check "Browser cache owned by user" bash -c "[ \"\$(stat -c '%U' ${USER_HOME}/.cache/ms-playwright)\" = \"${CURRENT_USER}\" ]"
19+
20+
# Verify browsers are not installed in root directory (if we're not root)
21+
if [ "${CURRENT_USER}" != "root" ]; then
22+
check "Browser cache not in root" bash -c "! test -d /root/.cache/ms-playwright || [ \"\$(ls -A /root/.cache/ms-playwright 2>/dev/null | wc -l)\" = \"0\" ]"
23+
fi
24+
25+
# Test that browsers can be listed (validates installation)
26+
check "Can list browsers" npx playwright install --list
27+
28+
# Verify the user can run playwright commands without permission issues
29+
check "User can run playwright" bash -c 'npx playwright --help | grep -q "Usage"'
30+
31+
reportResults

0 commit comments

Comments
 (0)