Repository navigation
Fix Playwright dev container feature to install browsers under non-root user #82
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
schlich
merged 7 commits into
main
from
copilot/fix-5411878d-0653-4b37-9ec3-22f3412632a7
Oct 2, 2025
Merged
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
372f34e
Initial plan
Copilot 512025e
Fix Playwright installation to respect non-root user
Copilot 57843ce
Improve Playwright user installation with PATH preservation
Copilot a884248
Update src/playwright/install.sh
schlich ec044c5
Update src/playwright/install.sh
schlich c72074d
Simplify installation using lifecycle hooks
Copilot d195d7f
Fix test compatibility by reverting to install.sh approach
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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)") | ||
| 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}" | ||
|
schlich marked this conversation as resolved.
Resolved
|
||
| fi | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.