运行环境

docker: Docker version 24.0.5, build 24.0.5-0ubuntu1~22.04.1
ubuntu: 22.04
playwright image: itisfoundation/osparc-playwright-e2e:2024-05
maven image: maven:3.8.5-openjdk-17-slim

报错信息

Caused by: com.microsoft.playwright.impl.TargetClosedError: Error {
  message='Target page, context or browser has been closed
Browser logs:
Chromium sandboxing failed!
================================
To workaround sandboxing issues, do either of the following:
  - (preferred): Configure environment to support sandboxing: https://playwright.dev/docs/troubleshooting
  - (alternative): Launch Chromium without sandbox using 'chromiumSandbox: false' option
================================

  name='TargetClosedError
  stack='TargetClosedError: Target page, context or browser has been closed
Browser logs:
Chromium sandboxing failed!
================================
To workaround sandboxing issues, do either of the following:
  - (preferred): Configure environment to support sandboxing: https://playwright.dev/docs/troubleshooting
  - (alternative): Launch Chromium without sandbox using 'chromiumSandbox: false' option
================================

    at DispatcherConnection.dispatch (/tmp/playwright-java-16072242212041617245/package/lib/server/dispatchers/dispatcher.js:379:15)
}
Call log:
- <launching> /ms-playwright/chromium-1105/chrome-linux/chrome --disable-field-trial-config --disable-background-networking --enable-features=NetworkService,NetworkServiceInProcess --disable-background-timer-throttling --disable-backgrounding-occluded-windows --disable-back-forward-cache --disable-breakpad --disable-client-side-phishing-detection --disable-component-extensions-with-background-pages --disable-component-update --no-default-browser-check --disable-default-apps --disable-dev-shm-usage --disable-extensions --disable-features=ImprovedCookieControls,LazyFrameLoading,GlobalMediaControls,DestroyProfileOnBrowserClose,MediaRouter,DialMediaRouteProvider,AcceptCHFrame,AutoExpandDetailsElement,CertificateTransparencyComponentUpdater,AvoidUnnecessaryBeforeUnloadCheckSync,Translate,HttpsUpgrades,PaintHolding --allow-pre-commit-input --disable-hang-monitor --disable-ipc-flooding-protection --disable-popup-blocking --disable-prompt-on-repost --disable-renderer-backgrounding --force-color-profile=srgb --metrics-recording-only --no-first-run --enable-automation --password-store=basic --use-mock-keychain --no-service-autorun --export-tagged-pdf --disable-search-engine-choice-screen --headless --hide-scrollbars --mute-audio --blink-settings=primaryHoverType=2,availableHoverTypes=2,primaryPointerType=4,availablePointerTypes=4 --proxy-server=http://127.0.0.1:10809 --proxy-bypass-list=<-loopback> --user-data-dir=/tmp/playwright_chromiumdev_profile-bVtNIz --remote-debugging-pipe --no-startup-window
- <launched> pid=900
- [pid=900][err] [0604/094626.949594:ERROR:zygote_host_impl_linux.cc(100)] Running as root without --no-sandbox is not supported. See https://crbug.com/638180.

        at com.microsoft.playwright.impl.Connection.dispatch(Connection.java:256) ~[playwright-1.42.0.jar!/:1.42.0]
        at com.microsoft.playwright.impl.Connection.processOneMessage(Connection.java:211) ~[playwright-1.42.0.jar!/:1.42.0]
        at com.microsoft.playwright.impl.ChannelOwner.runUntil(ChannelOwner.java:118) ~[playwright-1.42.0.jar!/:1.42.0]
        ... 56 common frames omitted

问题分析

报错中有“Chromium sandboxing failed!”字样,推测是该配置问题。
检查配置发现,代码中将ChromiumSandbox配置设为了true,尝试修改为false后可以正常运行。
所以说,该运行环境不支持Chromium的沙箱配置。

解决方案

将配置ChromiumSandbox配置为false即可。

已经向官方提issue,等待后续更新。

参考

[1] playwright docker doc

[2] microsoft-playwright-java image