Closed pablopioli closed 3 years ago
So, after a lot of trial and error and learning a lot about Linux and how Playwright works I found a workaround.
The problem is in playwright.sh. The current contents are
SCRIPT_PATH="$(cd "$(dirname "$0")" ; pwd -P)"
$SCRIPT_PATH/node $SCRIPT_PATH/package/lib/cli/cli.js "$@"
xvfb is already installed in the base image of Playwright but PlaywrightSharp does not use it. To enable the restful mode I developed this workaround. I modified the playwright.sh file and inject the updated file in the image on build.
SCRIPT_PATH="$(cd "$(dirname "$0")" ; pwd -P)"
xvfb-run -a $SCRIPT_PATH/node $SCRIPT_PATH/package/lib/cli/cli.js "$@"
Obviously the image is an all or nothing now, running all workloads with X window enabled.
I suppose this can be fixed in PlaywrightSharp. I can build a pull request of it. But, I would like to hear from the maintainers how to implement it without interfering with the current architecture.
Options I came with:
Those are options that can impact the current design, so I take it as a design decision mainly.
First, the .sh
file comes from upstream (https://github.com/microsoft/playwright/blob/master/utils/build/run-driver-posix.sh), so I don't think changing it will be the right approach - but I could be wrong.
That said, I remember @stuartleeks had a working approach (granted not for the .NET port, but it should still be fine). Stuart, if this resonates, can you chime in with what you did?
I'm running on Windows with playwright (JS) in a VS Code dev container. I run an X Server on my windows host (such as vcxsrv) and in my dev container I set the DISPLAY
to the IP address of the host (I'm running my containers in the WSL backend for Docker Desktop). Without this, I saw similar Unable to open X display
errors as in your original post.
With this setup, the code runs in the dev container and the browser UI is shown via the X server.
Don't know whether that helps at all with your scenario?
One needs X server for headed mode, xvfb-run
would be an option.
I have successfully made Playwright work in Docker. But a page requires to go in the headful mode.
Playwright image states that you can run in headful mode, but PlaywrightSharp cannot. On starting the browser you get: