Skip to content

[Feature]: Read PLAYWRIGHT_DRIVER_DIR from Playwright.CreateOptions.env #2050

Closed

Description

🚀 Feature Request

Since #1938, Driver can run from a driver directory that was extracted beforehand, via the playwright.cli.dir system property or the PLAYWRIGHT_DRIVER_DIR environment variable. Both are JVM-wide: Driver.newInstance() reads only System.getProperty and System.getenv.

Please also honour PLAYWRIGHT_DRIVER_DIR from the env map given to Playwright.create(new CreateOptions().setEnv(...)), per call. A PreinstalledDriver costs nothing to create, so when that map holds PLAYWRIGHT_DRIVER_DIR, PlaywrightImpl.createImpl can use a PreinstalledDriver for it instead of the JVM-wide instance of Driver.ensureDriverInstalled. This avoids the first-caller-wins behaviour that PLAYWRIGHT_NODEJS_PATH has when passed through CreateOptions.env (#1552).

Example

Path driverDir = Paths.get("/var/lib/my-service/playwright-driver");
if (!Files.exists(driverDir.resolve("package").resolve("cli.js"))) {
  DriverJar.installDriverTo(driverDir);
}
Map<String, String> env = new HashMap<>();
env.put("PLAYWRIGHT_DRIVER_DIR", driverDir.toString());
Playwright playwright = Playwright.create(new Playwright.CreateOptions().setEnv(env));

Motivation

We hit #728: a temporary files cleaner deletes the driver extracted under /tmp, and every later Playwright.create() fails with "Failed to launch driver" until the JVM restarts. installDriverTo plus PLAYWRIGHT_DRIVER_DIR fixes that, but only through a system property or the process environment.

Playwright is used here by a library embedded in applications that share one JVM (several web applications in one servlet container). A library cannot set process environment variables, and setting a system property affects every other application in the JVM, possibly on another Playwright version. Settings read by the driver process, such as PLAYWRIGHT_BROWSERS_PATH, already work per call through CreateOptions.env; the driver directory, read on the Java side, does not.

Activity

  1. microsoft-playwright-automation commented on Nov 18, 2026

    @microsoft-playwright-automation
  2. microsoft-playwright-automation commented on Nov 18, 2026

    @microsoft-playwright-automation

    Hi, I'm the Playwright bot. I checked the requested per-call behavior and #2051.

    Confirmed: main ignores PLAYWRIGHT_DRIVER_DIR from CreateOptions.env, and #2051 fixes it. At ebb6ebd2d2a010232ad142059fc4c824b424eb9a, each explicit directory is selected independently without replacing the shared default driver. I found no functional issues in the proposed fix.

    Verification on Linux

    On main (5fb7f0f442fa71f79cdfaa8a98113d41481c4b0a), an independent check returned the default temporary directory instead of the requested directory. On #2051, that check passed, including selecting a different directory on a second call, preserving the default driver, and running the selected driver's CLI.

    Both regression tests added by #2051 fail without its implementation. TestInstall and TestPlaywrightCreate passed all 17 tests on the PR and with its changes applied to current main. Creation tests ran with chromium, firefox, and webkit selected; these checks cover driver selection and startup, not browser rendering.

    Tested with the source-built 1.65.0 driver and JDK 17. The PR applies to current main without conflicts.

    Triaged on Linux by the Playwright bot - agent run

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions