microsoft / playwright

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
https://playwright.dev
Apache License 2.0
66.03k stars 3.6k forks source link

[BUG]headless mode should be on by default in container #22249

Closed ToddBradley closed 1 year ago

ToddBradley commented 1 year ago

Context:

Code Snippet

docker run -it --rm mcr.microsoft.com/playwright/python:v1.32.0 playwright open http://google.com
[Error: 
╔════════════════════════════════════════════════════════════════════════════════════════════════╗
║ Looks like you launched a headed browser without having a XServer running.                     ║
║ Set either 'headless: true' or use 'xvfb-run <your-playwright-app>' before running Playwright. ║
║                                                                                                ║
║ <3 Playwright Team                                                                             ║
╚════════════════════════════════════════════════════════════════════════════════════════════════╝
=========================== logs ===========================
<launching> /ms-playwright/chromium-1055/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 --allow-pre-commit-input --disable-hang-monitor --disable-ipc-flooding-protection --disable-popup-blocking --disable-prompt-on-repost --disable-renderer-backgrounding --disable-sync --force-color-profile=srgb --metrics-recording-only --no-first-run --enable-automation --password-store=basic --use-mock-keychain --no-service-autorun --export-tagged-pdf --no-sandbox --user-data-dir=/tmp/playwright_chromiumdev_profile-iHLsjW --remote-debugging-pipe --no-startup-window
<launched> pid=110
[pid=110][err] [110:125:0405/230318.118682:ERROR:bus.cc(399)] Failed to connect to the bus: Failed to connect to socket /var/run/dbus/system_bus_socket: No such file or directory
[pid=110][err] [110:110:0405/230318.145675:ERROR:ozone_platform_x11.cc(239)] Missing X server or $DISPLAY
[pid=110][err] [110:110:0405/230318.145696:ERROR:env.cc(255)] The platform failed to initialize.  Exiting.
============================================================]

Describe the bug

According to the documentation, "By default, Playwright launches browsers in headless mode." However, running Playwright via the Docker container tries to start Chrome, and - by default - fails.

The error message from the Playwright Team is clear about the problem. It says, "Looks like you launched a headed browser without having a XServer running." But since I provided no other command line arguments, the open command should have launched a headless browser, according to the documentation.

Given the choice between changing the documentation and changing the software running in the container, I think you should fix the latter. If I'm running containerized Playwright, I probably want it to be headless.

pavelfeldman commented 1 year ago

But since I provided no other command line arguments, the open command should have launched a headless browser, according to the documentation.

open obviously opens a GUI browser, otherwise there isn't much you can do with it.