Open msangel opened 1 year ago
As long as the image tag matches playwright version you use in the project, the image should already contain all 3 browsers downloaded (in /ms-playwright
directory) and all playwright maven packages cached locally (under /root/.m2/repository/com/microsoft/playwright
). Please make sure you use playwright version that matches the image. If Playwright still downloads browsers or its packages from the network we'll need a repro.
A bit more on each of the items from the observed behavior section:
- java playwright detects no node.js installed
Playwright doesn't detect if node.js is installed on the system, instead it uses the one that is shipped in driver-bundle package. This is a deliberate decision. We can change this model in the future but it has served well so far. There is a related feature request: https://github.com/microsoft/playwright-java/issues/1196. Also, you can manually specify alternative node.js location via PLAYWRIGHT_NODEJS_PATH or entire driver location via playwright.cli.dir. If you specify the latter playwright will not extract anything from the driver bundle.
- java playwright unpack node.js in tmp folder
Yes, this happens on every launch of playwright java. Unfortunately, Maven doesn't provide any means for extracting a bundled executable into a managed location.
- java playwright can't see installed browsers
As I mentioned above this is likely because of the version mismatch.
- java playwright download browsers into temp directory
The browsers are downloaded into a cache directory managed by playwright rather than /tmp. See this page for more details.
Closing per the response above, feel free to open a new issue if it doesn't work.
Doesn't.
I have dived into this more and these is problems the library has:
Anyway. Even manually crafting base image with such capabilities close to impossible, as there is no tooling to unpack driver to any location. I literally had to unzip it from jar and put binaries to docker fs. My approach will fail next time maven dependency is upgraded (it anyway will fail as the library already rely on a specific base image version via PLAYWRIGHT_BROWSERS_PATH
)
Tradeof will provide tooling for unpacking driver to specific location
As the environment I work on explicitly disallows dynamically-created shell script execution. Sad to hear that Microsoft allows such.
Preinstalling Node.js and driver in Docker images once makes total sense. We may even try to switch to the mode where we download Node.js and the driver to a local cache when starting Playwright the same way as we download browsers today. That has been a low priority task so far but we might find some resources to work on this.
@msangel / @yury-s I have the similar requirement. Installing only required playwright packages in existing Docker image.
I have an existing docker image of my Java based application. I want to open web page in headless browser mode in my existing java application using playwright java library. Can you please help me with this. I want install required packages in my docker image from playwright docker image.
Can you please help me understand, how did you do this? Any sample code or DockerFile will be helpful ?
Right now java library when running in the playwright/java docker image is not aware of installed browsers automatically. Also Even having a lot of things installed, the library requires node.js instalation that is not bundled with image(yes, it bundled with the library itself, but this have some drawbacks, see below).
Right now running java application with this library inside of playwright/java container with default settings behaves the same way as it would behave on empty+java base image. When the application started and playwright API is called, these steps happen:
Expected behavior: