diff --git a/src/playwright/NOTES.md b/src/playwright/NOTES.md new file mode 100644 index 0000000..c3ecc5e --- /dev/null +++ b/src/playwright/NOTES.md @@ -0,0 +1,23 @@ +## Requirements + +Select the node feature alongside this one. The install uses `npm` and exits with an explicit error +when it cannot find it — it never installs node for you, so your own version pin stays intact. + +```json +"features": { + "ghcr.io/devcontainers/features/node:2": {}, + "ghcr.io/orianna-ai/devcontainer-features/playwright:1": {} +} +``` + +Debian and Ubuntu only. Playwright installs Chromium's shared libraries with apt and has no +equivalent for other package managers. + +## Browsers + +Chromium only, plus the headless shell and ffmpeg that come with it. Firefox and WebKit are not +downloaded. + +They live in `/usr/local/share/ms-playwright` rather than Playwright's default `$HOME/.cache`, and +`PLAYWRIGHT_BROWSERS_PATH` is set through `containerEnv` to match. Nothing to configure, and it +keeps working when `HOME` is replaced at run time. diff --git a/src/playwright/README.md b/src/playwright/README.md new file mode 100644 index 0000000..f6faee0 --- /dev/null +++ b/src/playwright/README.md @@ -0,0 +1,47 @@ + +# Playwright (playwright) + +Installs the Playwright CLI and Chromium. Requires the node feature. + +## Example Usage + +```json +"features": { + "ghcr.io/orianna-ai/devcontainer-features/playwright:1": {} +} +``` + +## Options + +| Options Id | Description | Type | Default Value | +|-----|-----|-----|-----| +| version | Version of the @playwright/cli package to install. | string | latest | + +## Requirements + +Select the node feature alongside this one. The install uses `npm` and exits with an explicit error +when it cannot find it — it never installs node for you, so your own version pin stays intact. + +```json +"features": { + "ghcr.io/devcontainers/features/node:2": {}, + "ghcr.io/orianna-ai/devcontainer-features/playwright:1": {} +} +``` + +Debian and Ubuntu only. Playwright installs Chromium's shared libraries with apt and has no +equivalent for other package managers. + +## Browsers + +Chromium only, plus the headless shell and ffmpeg that come with it. Firefox and WebKit are not +downloaded. + +They live in `/usr/local/share/ms-playwright` rather than Playwright's default `$HOME/.cache`, and +`PLAYWRIGHT_BROWSERS_PATH` is set through `containerEnv` to match. Nothing to configure, and it +keeps working when `HOME` is replaced at run time. + + +--- + +_Note: This file was auto-generated from the [devcontainer-feature.json](devcontainer-feature.json). Add additional notes to a `NOTES.md`._ diff --git a/src/playwright/devcontainer-feature.json b/src/playwright/devcontainer-feature.json new file mode 100644 index 0000000..033fe30 --- /dev/null +++ b/src/playwright/devcontainer-feature.json @@ -0,0 +1,20 @@ +{ + "containerEnv": { + "PLAYWRIGHT_BROWSERS_PATH": "/usr/local/share/ms-playwright" + }, + "description": "Installs the Playwright CLI and Chromium. Requires the node feature.", + "id": "playwright", + "installsAfter": [ + "ghcr.io/devcontainers/features/common-utils", + "ghcr.io/devcontainers/features/node" + ], + "name": "Playwright", + "options": { + "version": { + "default": "latest", + "description": "Version of the @playwright/cli package to install.", + "type": "string" + } + }, + "version": "1.0.0" +} diff --git a/src/playwright/install.sh b/src/playwright/install.sh new file mode 100755 index 0000000..4548c6e --- /dev/null +++ b/src/playwright/install.sh @@ -0,0 +1,48 @@ +#!/bin/bash +set -euo pipefail + +VERSION="${VERSION:-latest}" +BROWSERS_PATH="/usr/local/share/ms-playwright" + +export DEBIAN_FRONTEND=noninteractive +export PLAYWRIGHT_BROWSERS_PATH="${BROWSERS_PATH}" + +if ! command -v apt-get >/dev/null 2>&1; then + echo "apt-get was not found; this feature only supports debian and ubuntu base images" >&2 + exit 1 +fi + +if ! command -v npm >/dev/null 2>&1; then + export NVM_DIR="${NVM_DIR:-/usr/local/share/nvm}" + + # shellcheck source=/dev/null + [ -s "${NVM_DIR}/nvm.sh" ] && . "${NVM_DIR}/nvm.sh" +fi + +if ! command -v npm >/dev/null 2>&1; then + echo "npm was not found; this feature has to install after the node feature" >&2 + exit 1 +fi + +npm_root="$(npm root -g)" +owner="$(stat -c '%u:%g' "${npm_root}")" + +npm install --global "@playwright/cli@${VERSION}" + +playwright_core="$(find "${npm_root}" -maxdepth 6 -path '*/playwright-core/cli.js' -print -quit)" + +if [ -z "${playwright_core}" ]; then + echo "playwright-core was not found under ${npm_root}" >&2 + exit 1 +fi + +apt-get update -y + +node "${playwright_core}" install-deps chromium +node "${playwright_core}" install chromium + +rm -rf /var/lib/apt/lists/* +npm cache clean --force + +chown -R "${owner}" "${npm_root}" "$(npm prefix -g)/bin" "${BROWSERS_PATH}" +chmod -R a+rX "${BROWSERS_PATH}" diff --git a/test/playwright/scenarios.json b/test/playwright/scenarios.json new file mode 100644 index 0000000..4a921e5 --- /dev/null +++ b/test/playwright/scenarios.json @@ -0,0 +1,13 @@ +{ + "ubuntu": { + "features": { + "ghcr.io/devcontainers/features/common-utils:2": {}, + "ghcr.io/devcontainers/features/node:1": {}, + "playwright": { + "version": "latest" + } + }, + "image": "mcr.microsoft.com/devcontainers/base:ubuntu-22.04", + "user": "vscode" + } +} diff --git a/test/playwright/ubuntu.sh b/test/playwright/ubuntu.sh new file mode 100755 index 0000000..fffdef3 --- /dev/null +++ b/test/playwright/ubuntu.sh @@ -0,0 +1,11 @@ +#!/bin/bash +set -e + +# shellcheck source=/dev/null +source \ + dev-container-features-test-lib +check 'check if playwright-cli exists' bash -c "command -v playwright-cli" +check 'check if the browsers path is exported' bash -c "test \"${PLAYWRIGHT_BROWSERS_PATH:-}\" = /usr/local/share/ms-playwright" +check 'check if chromium was downloaded' bash -c "ls /usr/local/share/ms-playwright | grep -q chromium" +check 'check if the browsers are readable by the remote user' bash -c "test -r /usr/local/share/ms-playwright && test -x /usr/local/share/ms-playwright" +reportResults