From 5776f4544c93c496c71ca2e8c1f3fe93b33b096c Mon Sep 17 00:00:00 2001 From: andrewbelcher Date: Wed, 4 Mar 2026 20:58:41 +0000 Subject: [PATCH] Add playwright to the project to share browser versions with packages such as vite/browser-playwright for vitest. --- config.playwright-cli.yaml | 10 +++++++++- tests/test.bats | 8 ++++++++ web-build/Dockerfile.playwright-cli | 6 ++---- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/config.playwright-cli.yaml b/config.playwright-cli.yaml index 8e0951c..8fec894 100644 --- a/config.playwright-cli.yaml +++ b/config.playwright-cli.yaml @@ -1,7 +1,15 @@ #ddev-generated hooks: post-start: + # Ensure playwright-cli is installed. + - exec: "[ -x /var/www/html/node_modules/.bin/playwright-cli ] || npm install --save-dev @playwright/cli" + # Symlink so it can be called directly. + - exec: "ln -sf /var/www/html/node_modules/.bin/playwright-cli /usr/local/bin/playwright-cli" + # Install chromium and playwright-cli skills. + - exec: "playwright-cli install chromium" - exec: "[[ -d /var/www/html/.claude/skills/playwright-cli ]] || playwright-cli install --skills" + # Configure the cert store for DDEV/mkcert from the host. - exec: mkdir -p $HOME/.pki/nssdb && certutil -d sql:$HOME/.pki/nssdb -N --empty-password && certutil -d sql:$HOME/.pki/nssdb -A -t "C,," -n mkcert-ca -i $(mkcert -CAROOT)/rootCA.pem web_environment: -- PLAYWRIGHT_MCP_BROWSER=chromium + - PLAYWRIGHT_BROWSERS_PATH=/mnt/ddev-global-cache/playwright-browsers + - PLAYWRIGHT_MCP_BROWSER=chromium diff --git a/tests/test.bats b/tests/test.bats index 9027e0e..5e67a01 100644 --- a/tests/test.bats +++ b/tests/test.bats @@ -51,6 +51,14 @@ health_checks() { assert_line "### Page" assert_line "- Page URL: https://example.com/" assert_line "- Page Title: Example Domain" + + # Check that it can be executed directly in the container. + DDEV_DEBUG=true run ddev exec playwright-cli open https://example.com/ + assert_success + assert_line " - browser-type: chromium" + assert_line "### Page" + assert_line "- Page URL: https://example.com/" + assert_line "- Page Title: Example Domain" } teardown() { diff --git a/web-build/Dockerfile.playwright-cli b/web-build/Dockerfile.playwright-cli index 025be79..11bde39 100644 --- a/web-build/Dockerfile.playwright-cli +++ b/web-build/Dockerfile.playwright-cli @@ -1,8 +1,6 @@ #ddev-generated -RUN npm install -g @playwright/cli@latest -RUN npx playwright install-deps chromium -# Install chromium as the user. -RUN mkdir /.playwright && chmod 0777 /.playwright && sudo -u ${username} playwright-cli install chromium +# Install Chromium OS dependencies (version-independent). +RUN npx -y playwright install-deps chromium # Add the mkcert certificate authority. RUN apt-get update && apt-get install -y libnss3-tools