Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Consider splitting driver dependencies #1196

Open
sephiroth-j opened this issue Feb 6, 2023 · 4 comments
Open

[Feature] Consider splitting driver dependencies #1196

sephiroth-j opened this issue Feb 6, 2023 · 4 comments

Comments

@sephiroth-j
Copy link

sephiroth-j commented Feb 6, 2023

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".

@yury-s
Copy link
Member

yury-s commented Feb 6, 2023

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.

@sephiroth-j
Copy link
Author

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>

@lin-mt
Copy link

lin-mt commented Sep 5, 2023

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

@Tsyklop
Copy link

Tsyklop commented Dec 25, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants