playwright-java icon indicating copy to clipboard operation
playwright-java copied to clipboard

[Feature] Consider splitting driver dependencies

Open sephiroth-j opened this issue 2 years ago • 4 comments

The driver bundle is one big jar containing all the drivers for every supported platform. This makes it quite large, roughly 117 MB for v1.29.0.

The "driver-bundle" artifact could be changed to be only a very small artifact with runtime dependencies for each driver and platform. This would allow users to exclude drivers and platforms they don't need. For example, if someone only needs Chromium on Windows x86-64, Maven's method of excluding dependencies could be used to reduce the download size.

So, in the future, one could have a variant of "driver-bundle" that includes only the shared parts for all drivers and depends on "driver-chromium" (with shared parts for each platform), "driver-chromium-linux" (Linux parts only), and "driver-chromium-windows" (Windows parts only). "driver-chromium-linux" may also depend on "chromium-linux-x86-64" and "chromium-linux-arm64".

sephiroth-j avatar Feb 06 '23 15:02 sephiroth-j

We contemplated having some filters for the driver deps in the past but were not satisfied with the mechanisms that Maven provides for defining platform-specific modules. Using exclusion in the client config sounds like an interesting alternative. It seems to be breaking what the package author assumes about the dependencies, so I'm not 100% sure we want to recommend that. I'll keep this request open to collect more feedback.

Note also that we only bundle driver binaries which include node executable and relevant playwright node.js code. All browsers are downloaded separately and only include those that are required for the host platform. See this page for more information on how playwright manages browser downloads.

For the time being you have to options to mitigate the proble:

  • Use preinstalled driver and configure the path via system property or
  • Configure playwright to use your own implementation of the Driver loader.

yury-s avatar Feb 06 '23 21:02 yury-s

Thanks, I am overall happy with how Playwright works.

If you add the dependencies in "driver-bundle" as follows, then nothing changes for the users. "driver-bundle" is still sufficient as dependency and the new platform-specific dependencies are automatically loaded as transitive dependencies. The only difference is that now you have the possibility to exclude the unnecessary platform-specific dependencies. This would also be interesting for Node.js, where you have the possibility to use your own pre-installed version of Node.js since #1016. Especially in CI environments, where the images may already have Node.js, browser and drivers installed, this is a useful feature to save traffic and time.

<project>
  <parent>
    <groupId>com.microsoft.playwright</groupId>
    <artifactId>parent-pom</artifactId>
    <version>x.y.z</version>
  </parent>

  <artifactId>driver-bundle</artifactId>

  <dependencies>
    <dependency>
      <groupId>com.microsoft.playwright</groupId>
      <artifactId>driver</artifactId>
      <version>${project.version}</version>
      <scope>compile</scope>
    </dependency>
    <!-- new platform specific stuff comes here -->
    <dependency>
      <groupId>com.microsoft.playwright</groupId>
      <artifactId>driver-node-mac</artifactId>
      <version>${project.version}</version>
      <scope>runtime</scope>
    </dependency>
    <!-- new platform specific stuff ends here -->
    <dependency>
      <groupId>org.junit.jupiter</groupId>
      <artifactId>junit-jupiter-engine</artifactId>
    </dependency>
  </dependencies>
</project>

sephiroth-j avatar Feb 07 '23 09:02 sephiroth-j

The current docker image is too large, and we only need to use chrome.

lin-mt avatar Sep 05 '23 07:09 lin-mt

I have multimodule project.
I solve this problem with next trick:

Createed module without java code. Added playwright dependency and maven-assembly-plugin.

Added assembly.xml for maven plugin:

<?xml version='1.0' encoding='UTF-8'?>
<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.2.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.2.0 https://maven.apache.org/xsd/assembly-2.2.0.xsd">
    <id>exclude-playwright-drivers</id>
    <formats>
        <format>jar</format>
    </formats>
    <includeBaseDirectory>false</includeBaseDirectory>
    <dependencySets>
        <dependencySet>
            <unpack>true</unpack>
            <scope>runtime</scope>
            <outputDirectory>/</outputDirectory>
            <useProjectArtifact>true</useProjectArtifact>
            <unpackOptions>
                <excludes>
                    <exclude>driver/linux</exclude>
                    <exclude>driver/linux/**</exclude>
                    <exclude>driver/linux-arm64</exclude>
                    <exclude>driver/linux-arm64/**</exclude>
                    <exclude>driver/mac</exclude>
                    <exclude>driver/mac/**</exclude>
                    <exclude>driver/mac-arm64</exclude>
                    <exclude>driver/mac-arm64/**</exclude>
                </excludes>
            </unpackOptions>
        </dependencySet>
    </dependencySets>
</assembly>

Excluded what I do not need.
Excluded playwright dependencies from spring-boot-maven-plugin.

Added new module to main module dependencies list.

My final jar file reduced size from 200 MB to 60 MB

Tsyklop avatar Dec 25 '23 16:12 Tsyklop