October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
browser automation

How to Add Playwright to a Dockerized Java Application

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use a version-pinned Playwright Java dependency together with either Microsoft’s matching Playwright Java Docker image or your own Linux image with Playwright browsers and operating-system dependencies installed. Keep the Maven version and image tag aligned, run the container with --init (and usually --ipc=host for Chromium), then execute your tests with the browser binaries available in the image.

What you need before building

  • A Java application built with Maven or Gradle.
  • Docker Engine capable of running Linux containers.
  • A Playwright Java version you can pin in source control.
  • A decision between the official Playwright image and your existing application image.

Playwright for Java is distributed through Maven. The official installation guide demonstrates the com.microsoft.playwright:playwright dependency and launching Chromium with Playwright.create(). Browser executables are separate from the Java library. As the browser documentation states, “Each version of Playwright needs specific versions of browser binaries to operate.”

Choose an image strategy

Approach What you get Best when Trade-off
Official Playwright Java image Playwright browsers and required system packages are preinstalled. Test jobs and CI where a ready-to-run browser environment matters most. Your base image is determined by the published Playwright tag; your application dependency is still your responsibility.
Extend your existing Java image Your current JDK, OS packages and application layout, plus browsers installed during the build. You need a corporate base image, custom certificates or one production image for several processes. You must install and maintain browser binaries and Linux dependencies yourself.

The official Docker guide documents versioned Java tags such as mcr.microsoft.com/playwright/java:v1.63.0-noble. Tags and releases change, so check the current page when selecting one. The documented variants include Noble (Ubuntu 24.04 LTS), Jammy (Ubuntu 22.04 LTS) and Resolute (Ubuntu 26.04 LTS). Pin a complete tag rather than a floating version.

Option A: use the official Playwright Java image

This image includes browser binaries and browser system dependencies, but it does not include your project’s Playwright Java Maven dependency. Add that dependency to your application and use the same release number as the image.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

1. Pin Playwright in Maven

Replace 1.63.0 below with the release you selected, keeping it identical to the Docker tag:

<dependency>
  <groupId>com.microsoft.playwright</groupId>
  <artifactId>playwright</artifactId>
  <version>1.63.0</version>
</dependency>

The Java installation page’s compiler example uses source and target 1.8, but that is an example rather than a universal requirement. Set your Java runtime and compiler level to match your application and the currently supported Playwright release.

2. Add a minimal browser program

package com.example;

import com.microsoft.playwright.Browser;
import com.microsoft.playwright.BrowserType;
import com.microsoft.playwright.Page;
import com.microsoft.playwright.Playwright;

public class ScreenshotSmokeTest {
  public static void main(String[] args) {
    try (Playwright playwright = Playwright.create()) {
      Browser browser = playwright.chromium().launch(
          new BrowserType.LaunchOptions().setHeadless(true));
      Page page = browser.newPage();
      page.navigate("https://example.com");
      System.out.println(page.title());
      browser.close();
    }
  }
}

3. Build and run it

docker pull mcr.microsoft.com/playwright/java:v1.63.0-noble
docker build -t java-playwright .
docker run --rm --init --ipc=host java-playwright

A simple Dockerfile can copy your built JAR into the image:

FROM mcr.microsoft.com/playwright/java:v1.63.0-noble
WORKDIR /app
COPY target/app.jar app.jar
ENTRYPOINT ["java", "-jar", "app.jar"]

If your tests need source files, Maven or Gradle, or reports, copy those into a dedicated build stage and keep the runtime stage limited to what the test process needs.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Option B: install browsers in your existing Java image

Choose this route when you cannot change the base image. The dependency must be available before the CLI installs browser binaries, because the CLI comes from the Playwright Java artifact.

Maven Dockerfile example

FROM eclipse-temurin:21-jdk
WORKDIR /workspace
COPY pom.xml .
RUN mvn -q dependency:go-offline
COPY src src
RUN mvn -q package -DskipTests
RUN mvn exec:java -e 
  -Dexec.mainClass=com.microsoft.playwright.CLI 
  -Dexec.args="install --with-deps"
COPY . .
CMD ["mvn", "test"]

The documented combined command is:

mvn exec:java -e -D exec.mainClass=com.microsoft.playwright.CLI -D exec.args="install --with-deps"

Use install --with-deps chromium when Chromium is the only browser required. The browser guide also documents install-deps when you want operating-system packages handled separately from browser downloads.

Build-cache considerations

Put the dependency manifest before application source in the Dockerfile so Maven dependencies can be cached. Browser installation should occur after the Playwright version is fixed; changing that version must invalidate the layer and download the matching binaries.

Keep the library, image and OS compatible

Do not upgrade the Maven dependency while leaving an old Playwright image in place. A mismatch can stop Playwright from finding the expected executable. Treat the dependency and image tag as one versioned change, update them together, and record both in your build files.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Alpine and other musl-based distributions are not supported for the documented Firefox and WebKit builds, which target glibc. Use a supported Ubuntu/Debian-based image when you need those browsers. If you only run Chromium, verify your chosen base image still has every package required by the current release.

Browser selection

  • Chromium: a common default for smoke tests and end-to-end checks.
  • Firefox or WebKit: install and test them explicitly; their system-library requirements make an unsupported musl base especially problematic.
  • All default browsers: run the CLI install without a browser name, accepting the larger image and build time.

Run the container safely and reliably

Use an init process

Pass --init so Docker supplies a proper PID 1 process and reaps child processes. This helps prevent zombie browser processes during repeated tests.

Give Chromium enough shared memory

Use --ipc=host for Chromium containers. The Docker guide recommends it because Chromium can otherwise exhaust the container’s shared-memory area and crash:

docker run --rm --init --ipc=host java-playwright

Privileges and untrusted pages

The official image runs as root by default, which disables Chromium’s sandbox. That can be acceptable for trusted end-to-end tests. It is not the recommended posture for crawling or scraping untrusted websites. In that case, create a separate non-root user and apply a seccomp profile that permits the user-namespace operations Chromium needs. The Playwright documentation describes the image as intended for testing and development, not as a hardened environment for untrusted browsing.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

During local troubleshooting, the Docker guide suggests trying --cap-add=SYS_ADMIN if Chromium launch errors persist. Do not treat that capability as a default production fix; investigate the user, sandbox and seccomp configuration instead.

Example non-root setup

FROM mcr.microsoft.com/playwright/java:v1.63.0-noble
USER root
RUN useradd --create-home --shell /bin/bash pwuser
USER pwuser
WORKDIR /home/pwuser/app
COPY --chown=pwuser:pwuser target/app.jar app.jar
ENTRYPOINT ["java", "-jar", "app.jar"]

Combine this with the seccomp configuration recommended in the official Docker guide for your deployment environment.

Run Playwright in CI

The Java CI guide follows a simple sequence: provide a Linux agent that can run browsers, install the Playwright library and browsers (or use the official image), then run the tests.

Maven on a Linux runner

mvn install -DskipTests
mvn exec:java -e -D exec.mainClass=com.microsoft.playwright.CLI -D exec.args="install --with-deps"
mvn test

Container-based CI

Use a versioned Playwright Java image in the job, install your project’s dependencies, and run Maven tests. The CI documentation includes examples for GitHub Actions, Azure Pipelines, CircleCI, Jenkins, Bitbucket Pipelines and GitLab CI; adapt the same version-pinning rule to whichever provider you use.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Caching browsers

Playwright advises against caching browser binaries by default: restoring a cache can take as long as downloading, and Linux operating-system dependencies are not cacheable. If you retain a cache, key it with a hash of the Playwright version so an upgrade cannot restore incompatible executables.

For browser-launch diagnostics, run:

DEBUG=pw:browser mvn test
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Common failures and fixes

Symptom Likely cause Fix
Executable does not exist or browser cannot be found The browser was never installed, or the image and Java dependency versions differ. Pin matching versions and rerun the CLI install in the image that actually runs the tests.
Missing shared libraries Your custom image lacks Linux browser packages. Use install --with-deps or the official image; check that the base distribution is supported.
Chromium crashes or reports out-of-memory errors Insufficient shared memory. Run with --ipc=host; also review container memory limits.
Zombie processes accumulate The Java process is PID 1 without an init reaper. Add --init or an equivalent init process.
Sandbox or permission errors Root execution disables Chromium’s sandbox, or a non-root user lacks the required seccomp allowance. Use root only for trusted tests; otherwise configure a separate user and the documented seccomp profile.
Firefox or WebKit fails on Alpine Those documented builds require glibc rather than musl. Use a supported glibc-based image.
CI is slow after every dependency change Browser downloads are repeated or a stale cache is restored. Order Docker layers for caching, or use a version-keyed cache only when it is demonstrably beneficial.

Or skip the browser setup

If your goal is simply to obtain a clean screenshot from a URL rather than maintain browser infrastructure, ScreenshotNeo provides a website screenshot API and MCP server. A single request returns PNG, JPEG, WebP or PDF. Cookie/consent banners are accepted and removed before capture, along with more than 60 known consent platforms, newsletter popups and chat widgets. Bot checks, blank pages, timeouts, failed loads and cache hits are not billed, and response headers identify the page verdict and billing result.

cURL:

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

Python:

import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"}, timeout=90)
open("shot.webp", "wb").write(r.content)

Node.js:

const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);

See the ScreenshotNeo API documentation for authentication and options. Its MCP server exposes take_screenshot, get_page_info and capture_pdf to Claude, Cursor and other MCP clients. The free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 shots. Create a free ScreenshotNeo account.

Design checklist

  • Pin the Playwright Java dependency and Docker image to the same release.
  • Install browsers in the final image, not only in an intermediate build stage.
  • Use a glibc-based supported distribution for Firefox and WebKit.
  • Run Chromium with --ipc=host and containers with --init.
  • Choose root only for trusted tests; use a separate user and seccomp profile for untrusted targets.
  • Log the Playwright version, image tag and browser-install command in CI output.
  • Enable DEBUG=pw:browser when launch diagnostics are needed.

Further official references

Frequently Asked Questions

Does the official Playwright Java image include the Maven dependency?

No. It includes browser binaries and system dependencies; your Maven or Gradle project must still declare the Playwright Java library.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Can I use Playwright Java on Alpine Linux?

The documented Firefox and WebKit browser builds target glibc, so use a supported glibc-based distribution when you need those browsers.

Should browser binaries be cached in CI?

Not by default. Playwright notes that restoring a cache can take as long as downloading and operating-system dependencies cannot be cached; if you cache, key it to the Playwright version.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Read next

Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.