PlaywrightがDocker環境へインストールできない

Docker(Dev Container)で構築した環境へPlaywrightがインストールできない
root@ed19525d0f3f:/home/node/app# yarn add playwright@1.36.1
yarn add v1.22.19
warning package-lock.json found. Your project contains lock files generated by tools other than Yarn. It is advised not to mix package managers in order to avoid resolution inconsistencies caused by unsynchronized lock files. To clear this warning, remove package-lock.json.
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
[-/3] ⢀ waiting...
[2/3] ⢀ esbuild
error /home/node/app/node_modules/playwright: Command failed.
Exit code: 1
Command: node install.js
Arguments:
Directory: /home/node/app/node_modules/playwright
Output:
/home/node/app/node_modules/playwright-core/lib/server/registry/index.js:684
if (!downloadURLs.length) throw new Error(`ERROR: Playwright does not support ${descriptor.name} on ${_hostPlatform.hostPlatform}`);
^
Error: ERROR: Playwright does not support firefox on debian12
at Registry._downloadExecutable (/home/node/app/node_modules/playwright-core/lib/server/registry/index.js:684:37)
at Object._install (/home/node/app/node_modules/playwright-core/lib/server/registry/index.js:463:28)
at Registry.install (/home/node/app/node_modules/playwright-core/lib/server/registry/index.js:642:26)
at async installBrowsersForNpmInstall (/home/node/app/node_modules/playwright-core/lib/server/registry/index.js:832:3)

debian 12のfirefoxに対応していない
ERROR: Playwright does not support firefox on debian12
11だと対応してるっぽい
System requirements
Node.js 16+
Windows 10+, Windows Server 2016+ or Windows Subsystem for Linux (WSL).
MacOS 12 Monterey or MacOS 13 Ventura.
Debian 11, Ubuntu 20.04 or Ubuntu 22.04.

Dockerで使用しているnodeイメージは18.16.0-slim
Debianをベースにしてるらしい

DockerコンテナのDebianバージョンを確認
12になっている
これを下げればいける?
root@ed19525d0f3f:/home/node/app# cat /etc/debian_version
12.0
公式でも確認

16.17.1-slim使ってみた
debianはv10になってる
root@a57ccbfad570:/home/node/app# cat /etc/debian_version
10.13

Install Playwright operating system dependencies (requires sudo / root - can be done manually via 'sudo yarn playwright install-deps')? (y/N)
これをyesにするとまたエラーが出たので、一旦noにしたらインストールできた
✔ Success! Created a Playwright Test project at /home/node/app

テスト実行してみたら全コケした
Error: browserType.launch:
╔══════════════════════════════════════════════════════╗
║ Host system is missing dependencies to run browsers. ║
║ Missing libraries: ║
║ libsoup-2.4.so.1 ║
║ libgtk-3.so.0
さっき飛ばした以下のコマンドを実行してみる
sudo yarn playwright install-deps

OSがサポートされていないらしい
your OS is not officially supported by Playwright; installing dependencies for Ubuntu as a fallback

公式ではUbuntuのみサポートされているらしい。
Debianでテストするには必要なパッケージを手動でインストールする必要がある

VSCodeの拡張で対応可能そうなので試してみる

.devcontainerへ拡張を追加後、右下のポップアップからinstallを実行

もう一回devcontainerのコンテナへplaywrightをインストールする方法を試してみた
18.14.0-slimがDebian11だったのでやってみる

yarn create playwright実行したらこのエラーが出たが、もう一度実行したら成功した
CIの時にも出るらしいので不安・・・

example.spec.tsを実行したらWebkitだけSSL証明書のエラーが発生した
Error: page.goto: Unacceptable TLS certificate
=========================== logs ===========================
navigating to "https://playwright.dev/", waiting until "load"
とりあえず無視しとく
export default defineConfig({
use: {
ignoreHTTPSErrors: true,
},

一旦インストールはできたのでまとめ
- Playwrightの現行バージョン(v1.36.1)はDebian11に対応している
- NodeのDockerimageでslimを使用している場合、Debianではあるがバージョンが12だったり11だったりするので注意
- DockerHubを確認し適切なバージョンのものを使用する必要がある