From ecb6901ed21da64aa48eadf4405b3ee8fe521fd0 Mon Sep 17 00:00:00 2001 From: Yury Semikhatsky Date: Thu, 18 Jun 2026 10:29:25 -0700 Subject: [PATCH 1/2] feat(driver-bundle): split driver per platform and auto-select host Replace the single ~194MB driver-bundle (all platforms) with one artifact per platform: driver-bundle-mac-x64, driver-bundle-mac-arm64, driver-bundle-linux-x64, driver-bundle-linux-arm64 and driver-bundle-win-x64. driver-bundle now ships only DriverJar and uses OS-activated Maven profiles to pull in the matching platform artifact for the build host, so a Maven build resolves just the driver it needs with no extra configuration. driver-bundle-all aggregates every platform for cross-platform fat jars. Fixes: https://github.com/microsoft/playwright-java/issues/1196 --- CONTRIBUTING.md | 2 +- driver-bundle-all/pom.xml | 48 +++++++++ driver-bundle-linux-arm64/pom.xml | 33 +++++++ .../src/main/resources/.gitignore | 2 + driver-bundle-linux-x64/pom.xml | 33 +++++++ .../src/main/resources/.gitignore | 2 + driver-bundle-mac-arm64/pom.xml | 33 +++++++ .../src/main/resources/.gitignore | 2 + driver-bundle-mac-x64/pom.xml | 33 +++++++ .../src/main/resources/.gitignore | 2 + driver-bundle-win-x64/pom.xml | 33 +++++++ .../src/main/resources/.gitignore | 2 + driver-bundle/pom.xml | 99 ++++++++++++++++--- .../playwright/impl/driver/jar/DriverJar.java | 6 +- pom.xml | 36 +++++++ scripts/download_driver.sh | 55 ++++++----- tools/test-cli-fatjar/pom.xml | 3 +- 17 files changed, 377 insertions(+), 47 deletions(-) create mode 100644 driver-bundle-all/pom.xml create mode 100644 driver-bundle-linux-arm64/pom.xml create mode 100644 driver-bundle-linux-arm64/src/main/resources/.gitignore create mode 100644 driver-bundle-linux-x64/pom.xml create mode 100644 driver-bundle-linux-x64/src/main/resources/.gitignore create mode 100644 driver-bundle-mac-arm64/pom.xml create mode 100644 driver-bundle-mac-arm64/src/main/resources/.gitignore create mode 100644 driver-bundle-mac-x64/pom.xml create mode 100644 driver-bundle-mac-x64/src/main/resources/.gitignore create mode 100644 driver-bundle-win-x64/pom.xml create mode 100644 driver-bundle-win-x64/src/main/resources/.gitignore diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index cd67302b2..d457f3c32 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -20,7 +20,7 @@ git clone https://github.com/microsoft/playwright-java cd playwright-java ``` -2. Run the following script to download and assemble the Playwright driver for all platforms into `driver-bundle/src/main/resources/driver/` directory (browser binaries for Chromium, Firefox and WebKit will be automatically downloaded later on first Playwright run). +2. Run the following script to download and assemble the Playwright driver for all platforms, one per module, into the `driver-bundle-/src/main/resources/driver//` directories (browser binaries for Chromium, Firefox and WebKit will be automatically downloaded later on first Playwright run). ```bash scripts/download_driver.sh diff --git a/driver-bundle-all/pom.xml b/driver-bundle-all/pom.xml new file mode 100644 index 000000000..c3f7fb0d4 --- /dev/null +++ b/driver-bundle-all/pom.xml @@ -0,0 +1,48 @@ + + + 4.0.0 + + com.microsoft.playwright + parent-pom + 1.50.0-SNAPSHOT + + + driver-bundle-all + Playwright - Drivers For All Platforms + + Aggregates the Playwright driver for every supported platform (macOS, Linux and Windows). + Depend on this artifact when a single build must run on more than the host platform, for + example a cross-platform fat JAR. For the common case where only the host platform is needed, + rely on the transitive driver-bundle dependency, which selects the right platform automatically. + + + + + com.microsoft.playwright + driver-bundle-mac-x64 + ${project.version} + + + com.microsoft.playwright + driver-bundle-mac-arm64 + ${project.version} + + + com.microsoft.playwright + driver-bundle-linux-x64 + ${project.version} + + + com.microsoft.playwright + driver-bundle-linux-arm64 + ${project.version} + + + com.microsoft.playwright + driver-bundle-win-x64 + ${project.version} + + + diff --git a/driver-bundle-linux-arm64/pom.xml b/driver-bundle-linux-arm64/pom.xml new file mode 100644 index 000000000..80bf90fc1 --- /dev/null +++ b/driver-bundle-linux-arm64/pom.xml @@ -0,0 +1,33 @@ + + + 4.0.0 + + com.microsoft.playwright + parent-pom + 1.50.0-SNAPSHOT + + + driver-bundle-linux-arm64 + Playwright - Driver For Linux arm64 + + Playwright driver (Node.js binary and playwright-core package) for the Linux arm64 platform. + This artifact is normally selected automatically for the host platform via the driver-bundle + module; depend on it directly (or on driver-bundle-all) to bundle additional platforms. + + + + + + + org.apache.maven.plugins + maven-source-plugin + + true + + + + + diff --git a/driver-bundle-linux-arm64/src/main/resources/.gitignore b/driver-bundle-linux-arm64/src/main/resources/.gitignore new file mode 100644 index 000000000..045408616 --- /dev/null +++ b/driver-bundle-linux-arm64/src/main/resources/.gitignore @@ -0,0 +1,2 @@ +driver/ +local-driver/ diff --git a/driver-bundle-linux-x64/pom.xml b/driver-bundle-linux-x64/pom.xml new file mode 100644 index 000000000..d1737f047 --- /dev/null +++ b/driver-bundle-linux-x64/pom.xml @@ -0,0 +1,33 @@ + + + 4.0.0 + + com.microsoft.playwright + parent-pom + 1.50.0-SNAPSHOT + + + driver-bundle-linux-x64 + Playwright - Driver For Linux x64 + + Playwright driver (Node.js binary and playwright-core package) for the Linux x64 platform. + This artifact is normally selected automatically for the host platform via the driver-bundle + module; depend on it directly (or on driver-bundle-all) to bundle additional platforms. + + + + + + + org.apache.maven.plugins + maven-source-plugin + + true + + + + + diff --git a/driver-bundle-linux-x64/src/main/resources/.gitignore b/driver-bundle-linux-x64/src/main/resources/.gitignore new file mode 100644 index 000000000..045408616 --- /dev/null +++ b/driver-bundle-linux-x64/src/main/resources/.gitignore @@ -0,0 +1,2 @@ +driver/ +local-driver/ diff --git a/driver-bundle-mac-arm64/pom.xml b/driver-bundle-mac-arm64/pom.xml new file mode 100644 index 000000000..bf05c6e63 --- /dev/null +++ b/driver-bundle-mac-arm64/pom.xml @@ -0,0 +1,33 @@ + + + 4.0.0 + + com.microsoft.playwright + parent-pom + 1.50.0-SNAPSHOT + + + driver-bundle-mac-arm64 + Playwright - Driver For macOS arm64 + + Playwright driver (Node.js binary and playwright-core package) for the macOS arm64 platform. + This artifact is normally selected automatically for the host platform via the driver-bundle + module; depend on it directly (or on driver-bundle-all) to bundle additional platforms. + + + + + + + org.apache.maven.plugins + maven-source-plugin + + true + + + + + diff --git a/driver-bundle-mac-arm64/src/main/resources/.gitignore b/driver-bundle-mac-arm64/src/main/resources/.gitignore new file mode 100644 index 000000000..045408616 --- /dev/null +++ b/driver-bundle-mac-arm64/src/main/resources/.gitignore @@ -0,0 +1,2 @@ +driver/ +local-driver/ diff --git a/driver-bundle-mac-x64/pom.xml b/driver-bundle-mac-x64/pom.xml new file mode 100644 index 000000000..d33c0d6e4 --- /dev/null +++ b/driver-bundle-mac-x64/pom.xml @@ -0,0 +1,33 @@ + + + 4.0.0 + + com.microsoft.playwright + parent-pom + 1.50.0-SNAPSHOT + + + driver-bundle-mac-x64 + Playwright - Driver For macOS x64 + + Playwright driver (Node.js binary and playwright-core package) for the macOS x64 platform. + This artifact is normally selected automatically for the host platform via the driver-bundle + module; depend on it directly (or on driver-bundle-all) to bundle additional platforms. + + + + + + + org.apache.maven.plugins + maven-source-plugin + + true + + + + + diff --git a/driver-bundle-mac-x64/src/main/resources/.gitignore b/driver-bundle-mac-x64/src/main/resources/.gitignore new file mode 100644 index 000000000..045408616 --- /dev/null +++ b/driver-bundle-mac-x64/src/main/resources/.gitignore @@ -0,0 +1,2 @@ +driver/ +local-driver/ diff --git a/driver-bundle-win-x64/pom.xml b/driver-bundle-win-x64/pom.xml new file mode 100644 index 000000000..fe162f74a --- /dev/null +++ b/driver-bundle-win-x64/pom.xml @@ -0,0 +1,33 @@ + + + 4.0.0 + + com.microsoft.playwright + parent-pom + 1.50.0-SNAPSHOT + + + driver-bundle-win-x64 + Playwright - Driver For Windows x64 + + Playwright driver (Node.js binary and playwright-core package) for the Windows x64 platform. + This artifact is normally selected automatically for the host platform via the driver-bundle + module; depend on it directly (or on driver-bundle-all) to bundle additional platforms. + + + + + + + org.apache.maven.plugins + maven-source-plugin + + true + + + + + diff --git a/driver-bundle-win-x64/src/main/resources/.gitignore b/driver-bundle-win-x64/src/main/resources/.gitignore new file mode 100644 index 000000000..045408616 --- /dev/null +++ b/driver-bundle-win-x64/src/main/resources/.gitignore @@ -0,0 +1,2 @@ +driver/ +local-driver/ diff --git a/driver-bundle/pom.xml b/driver-bundle/pom.xml index df02c5c16..d820f47d9 100644 --- a/driver-bundle/pom.xml +++ b/driver-bundle/pom.xml @@ -10,10 +10,14 @@ driver-bundle - Playwright - Drivers For All Platforms + Playwright - Driver For The Host Platform - This module includes Playwright driver and related utilities for all supported platforms. - It is intended to be used on the systems where Playwright driver is not preinstalled. + This module loads the Playwright driver from the classpath (DriverJar) and, via the + platform-specific profiles below, pulls in the driver binaries for the host platform only. + Maven activates exactly one profile based on the build machine's operating system and + architecture, so a build downloads just the driver it needs. To bundle every platform (for + example a cross-platform fat JAR) depend on driver-bundle-all, or add the individual + driver-bundle-<platform> artifacts explicitly. @@ -29,17 +33,80 @@ - - - - - org.apache.maven.plugins - maven-source-plugin - - true - - - - + + + + driver-linux + + linuxamd64 + + + + com.microsoft.playwright + driver-bundle-linux-x64 + ${project.version} + runtime + + + + + driver-linux-arm64 + + linuxaarch64 + + + + com.microsoft.playwright + driver-bundle-linux-arm64 + ${project.version} + runtime + + + + + driver-mac + + macx86_64 + + + + com.microsoft.playwright + driver-bundle-mac-x64 + ${project.version} + runtime + + + + + driver-mac-arm64 + + macaarch64 + + + + com.microsoft.playwright + driver-bundle-mac-arm64 + ${project.version} + runtime + + + + + driver-win-x64 + + windows + + + + com.microsoft.playwright + driver-bundle-win-x64 + ${project.version} + runtime + + + + diff --git a/driver-bundle/src/main/java/com/microsoft/playwright/impl/driver/jar/DriverJar.java b/driver-bundle/src/main/java/com/microsoft/playwright/impl/driver/jar/DriverJar.java index 654ff6732..f6d9a16e1 100644 --- a/driver-bundle/src/main/java/com/microsoft/playwright/impl/driver/jar/DriverJar.java +++ b/driver-bundle/src/main/java/com/microsoft/playwright/impl/driver/jar/DriverJar.java @@ -183,20 +183,20 @@ private static String platformDir() { String arch = System.getProperty("os.arch").toLowerCase(); if (name.contains("windows")) { - return "win32_x64"; + return "win-x64"; } if (name.contains("linux")) { if (arch.equals("aarch64")) { return "linux-arm64"; } else { - return "linux"; + return "linux-x64"; } } if (name.contains("mac os x")) { if (arch.equals("aarch64")) { return "mac-arm64"; } else { - return "mac"; + return "mac-x64"; } } throw new RuntimeException("Unexpected os.name value: " + name); diff --git a/pom.xml b/pom.xml index d012e6882..78054ac4b 100644 --- a/pom.xml +++ b/pom.xml @@ -37,6 +37,12 @@ driver + driver-bundle-mac-x64 + driver-bundle-mac-arm64 + driver-bundle-linux-x64 + driver-bundle-linux-arm64 + driver-bundle-win-x64 + driver-bundle-all driver-bundle playwright @@ -64,6 +70,36 @@ driver-bundle ${project.version} + + com.microsoft.playwright + driver-bundle-all + ${project.version} + + + com.microsoft.playwright + driver-bundle-mac-x64 + ${project.version} + + + com.microsoft.playwright + driver-bundle-mac-arm64 + ${project.version} + + + com.microsoft.playwright + driver-bundle-linux-x64 + ${project.version} + + + com.microsoft.playwright + driver-bundle-linux-arm64 + ${project.version} + + + com.microsoft.playwright + driver-bundle-win-x64 + ${project.version} + com.google.code.gson gson diff --git a/scripts/download_driver.sh b/scripts/download_driver.sh index dba7f75d2..633ac364a 100755 --- a/scripts/download_driver.sh +++ b/scripts/download_driver.sh @@ -11,7 +11,8 @@ if [[ ($1 == '-h') || ($1 == '--help') ]]; then echo "This script downloads and assembles the Playwright driver for all platforms." echo "Each driver is assembled from the 'playwright-core' npm package and the matching" echo "Node.js binary from https://nodejs.org, the same way the upstream Playwright build" - echo "does it. The result is put under 'driver-bundle/src/main/resources/driver'." + echo "does it. Each platform is written to its own module under" + echo "'driver-bundle-/src/main/resources/driver/'." echo "" echo "Usage: scripts/download_driver.sh [option]" echo "" @@ -56,51 +57,53 @@ echo "Driver version: $DRIVER_VERSION" echo "Upstream commit: $GIT_HEAD" echo "Node.js version: $NODE_VERSION" -cd ../driver-bundle/src/main/resources - -if [[ -d 'driver' ]]; then - echo "Deleting existing drivers from $(pwd)" - rm -rf driver -fi - -mkdir -p driver -cd driver - -# Download the platform-independent driver package (playwright-core) once. -CORE_TGZ="$(pwd)/playwright-core-$DRIVER_VERSION.tgz" +# Each platform's driver is assembled into its own Maven module +# (driver-bundle-/src/main/resources/driver/), so that a consumer build +# only pulls in the driver for the host platform. See issue #1196. The platform token uses an +# - scheme (e.g. mac-x64) that matches both the artifact name and the directory that +# DriverJar.platformDir() looks up. +ROOT="$(cd .. && pwd)" + +# Download once into a temporary directory shared across platforms. +TMP_DIR="$(mktemp -d)" +trap 'rm -rf "$TMP_DIR"' EXIT +CORE_TGZ="$TMP_DIR/playwright-core-$DRIVER_VERSION.tgz" download "https://registry.npmjs.org/playwright-core/-/playwright-core-$DRIVER_VERSION.tgz" "$CORE_TGZ" # :: for ENTRY in \ - "mac:darwin-x64:tar.gz" \ + "mac-x64:darwin-x64:tar.gz" \ "mac-arm64:darwin-arm64:tar.gz" \ - "linux:linux-x64:tar.gz" \ + "linux-x64:linux-x64:tar.gz" \ "linux-arm64:linux-arm64:tar.gz" \ - "win32_x64:win-x64:zip" + "win-x64:win-x64:zip" do IFS=':' read -r PLATFORM NODE_SUFFIX ARCHIVE <<< "$ENTRY" - echo "Assembling driver for $PLATFORM to $(pwd)/$PLATFORM" - mkdir "$PLATFORM" + DEST="$ROOT/driver-bundle-$PLATFORM/src/main/resources/driver" + if [[ -d "$DEST" ]]; then + echo "Deleting existing driver from $DEST" + rm -rf "$DEST" + fi + mkdir -p "$DEST/$PLATFORM" + echo "Assembling driver for $PLATFORM to $DEST/$PLATFORM" # 1. playwright-core package contents -> $PLATFORM/package - tar -xzf "$CORE_TGZ" -C "$PLATFORM" + tar -xzf "$CORE_TGZ" -C "$DEST/$PLATFORM" # 2. Node.js binary and its license from the official Node.js distribution. NODE_DIR="node-v$NODE_VERSION-$NODE_SUFFIX" - NODE_ARCHIVE="$NODE_DIR.$ARCHIVE" + NODE_ARCHIVE="$TMP_DIR/$NODE_DIR.$ARCHIVE" download "https://nodejs.org/dist/v$NODE_VERSION/$NODE_DIR.$ARCHIVE" "$NODE_ARCHIVE" if [[ $ARCHIVE == "zip" ]]; then - unzip -joq "$NODE_ARCHIVE" "$NODE_DIR/node.exe" -d "$PLATFORM" - unzip -joq "$NODE_ARCHIVE" "$NODE_DIR/LICENSE" -d "$PLATFORM" + unzip -joq "$NODE_ARCHIVE" "$NODE_DIR/node.exe" -d "$DEST/$PLATFORM" + unzip -joq "$NODE_ARCHIVE" "$NODE_DIR/LICENSE" -d "$DEST/$PLATFORM" else - tar -xzf "$NODE_ARCHIVE" -C "$PLATFORM" --strip-components=2 "$NODE_DIR/bin/node" - tar -xzf "$NODE_ARCHIVE" -C "$PLATFORM" --strip-components=1 "$NODE_DIR/LICENSE" + tar -xzf "$NODE_ARCHIVE" -C "$DEST/$PLATFORM" --strip-components=2 "$NODE_DIR/bin/node" + tar -xzf "$NODE_ARCHIVE" -C "$DEST/$PLATFORM" --strip-components=1 "$NODE_DIR/LICENSE" fi rm -f "$NODE_ARCHIVE" done -rm -f "$CORE_TGZ" - echo "" echo "All drivers have been successfully assembled." echo "" diff --git a/tools/test-cli-fatjar/pom.xml b/tools/test-cli-fatjar/pom.xml index 916e92187..2d7911c44 100644 --- a/tools/test-cli-fatjar/pom.xml +++ b/tools/test-cli-fatjar/pom.xml @@ -29,9 +29,10 @@ playwright ${project.version} + com.microsoft.playwright - driver-bundle + driver-bundle-all ${project.version} From 81cd2a37c007a6b932f457528d446e445519a992 Mon Sep 17 00:00:00 2001 From: Yury Semikhatsky Date: Thu, 18 Jun 2026 10:39:54 -0700 Subject: [PATCH 2/2] docs(driver-bundle): document platform selection and Gradle usage Explain that Maven auto-selects the host platform driver, how to bundle every platform with driver-bundle-all, and that Gradle consumers must declare the driver explicitly because Gradle ignores Maven POM profiles. --- README.md | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/README.md b/README.md index e3e411c3b..49542f346 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,51 @@ public class PageScreenshot { } ``` +## Driver bundles and platform selection + +Playwright ships the driver (a Node.js binary plus the `playwright-core` package) as +per-platform Maven artifacts. With **Maven**, the right one is selected automatically for the +machine that runs the build, so depending on `playwright` is all you need — no extra +configuration: + +| Artifact | Platform | +| --- | --- | +| `driver-bundle-mac-x64` | macOS Intel | +| `driver-bundle-mac-arm64` | macOS Apple Silicon | +| `driver-bundle-linux-x64` | Linux x64 | +| `driver-bundle-linux-arm64` | Linux arm64 | +| `driver-bundle-win-x64` | Windows x64 | + +### Bundling every platform (cross-platform / fat JARs) + +The automatic selection picks the driver for the build host, so a JAR built on Linux contains +only the Linux driver. If you build on one OS and run on another (for example a distributable +fat JAR), depend on `driver-bundle-all`, which bundles every platform: + +```xml + + com.microsoft.playwright + driver-bundle-all + ${playwright.version} + +``` + +### Gradle + +Gradle does not evaluate the Maven POM profiles that drive the automatic selection, so a Gradle +build will not pick a platform on its own (and converting the dependency from Maven does not +carry the selection over). Declare the driver explicitly — either a single platform: + +```kotlin +runtimeOnly("com.microsoft.playwright:driver-bundle-linux-x64:$playwrightVersion") +``` + +or every platform: + +```kotlin +runtimeOnly("com.microsoft.playwright:driver-bundle-all:$playwrightVersion") +``` + ## Other languages More comfortable in another programming language? [Playwright](https://playwright.dev) is also available in