Skip to content

fix(registry): evaluate defaultCacheDirectory lazily - #41942

Merged
Devin Rousso (dcrousso) merged 1 commit into
microsoft:mainfrom
dcrousso:fix-41852
Jul 23, 2026
Merged

Devin Rousso (dcrousso) merged 1 commit into
microsoft:mainfrom
dcrousso:fix-41852

Conversation

@dcrousso

@dcrousso Devin Rousso (dcrousso) commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

defaultCacheDirectory used to be computed inside the PLAYWRIGHT_BROWSERS_PATH branch of registryDirectory, so setting that variable skipped the platform check

#39423 hoisted it into an eagerly evaluated module constant, so it now throws Unsupported platform: <platform> at import, before registryDirectory consults PLAYWRIGHT_BROWSERS_PATH

this regressed setups that point PLAYWRIGHT_BROWSERS_PATH at their own browsers on platforms without a default cache directory, such as Android/Termux

evaluate defaultCacheDirectory, defaultRegistryDirectory, and baseDaemonDir lazily so an explicit PLAYWRIGHT_BROWSERS_PATH is honored before any default cache directory is computed

registryDirectory still throws eagerly when no override is set, since there is nowhere to place browsers

fixes #41852

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

let _defaultCacheDirectory: string | undefined;

export const defaultRegistryDirectory = path.join(defaultCacheDirectory, 'ms-playwright');
// Evaluated lazily so an explicit PLAYWRIGHT_BROWSERS_PATH lets Playwright run on

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please drop all these useless comments!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's strip the useless comments.

`defaultCacheDirectory` used to be computed inside the `PLAYWRIGHT_BROWSERS_PATH` branch of `registryDirectory`, so setting that variable skipped the platform check

a later refactor hoisted it into an eagerly evaluated module constant, so it now throws `Unsupported platform: <platform>` at import, before `registryDirectory` consults `PLAYWRIGHT_BROWSERS_PATH`

this regressed setups that point `PLAYWRIGHT_BROWSERS_PATH` at their own browsers on platforms without a default cache directory, such as Android/Termux

evaluate `defaultCacheDirectory`, `defaultRegistryDirectory`, and `baseDaemonDir` lazily so an explicit `PLAYWRIGHT_BROWSERS_PATH` is honored before any default cache directory is computed

`registryDirectory` still throws eagerly when no override is set, since there is nowhere to place browsers
@github-actions

Copy link
Copy Markdown
Contributor

Test results for "tests 1"

5 flaky ⚠️ [chromium-library] › library/chromium/chromium.spec.ts:434 › should produce network events, routing, and annotations for Service Worker (advanced) `@realtime-time-library-chromium-linux`
⚠️ [chromium-library] › library/video.spec.ts:495 › screencast › should capture static page in persistent context Radoslav Kirilov (@smoke) `@chromium-ubuntu-22.04-node20`
⚠️ [chromium-library] › library/video.spec.ts:736 › screencast › should work with video+trace `@chromium-ubuntu-22.04-node22`
⚠️ [playwright-test] › ui-mode-trace.spec.ts:715 › should indicate current test status `@windows-latest-node22`
⚠️ [playwright-test] › ui-mode-trace.spec.ts:827 › should update state on subsequent run `@windows-latest-node22`

50308 passed, 1190 skipped


Merge workflow run.

@github-actions

Copy link
Copy Markdown
Contributor

Test results for "MCP"

1 failed
❌ [msedge] › mcp/cli-devtools.spec.ts:84 › request shows full request and response details @mcp-windows-latest-msedge

7794 passed, 1266 skipped


Merge workflow run.

@github-actions

Copy link
Copy Markdown
Contributor

Hi, I'm the Playwright bot and I took a first look at the CI failures here.

🟢 The one failure is a pre-existing flake — the PR looks clear

[msedge] › mcp/cli-devtools.spec.ts:84 › request shows full request and response details is a known low-rate flake on a test this PR doesn't touch. This PR only changes lazy evaluation of defaultCacheDirectory/registry paths, which the MCP DevTools request/response flow never exercises.

Details

Pre-existing flake / infra

  • [msedge] › mcp/cli-devtools.spec.ts:84 › request shows full request and response details — flake. The same test fails with the identical signature (expect(received).not.toBeNull()Received: null) on main at sha 4b0cc996 (firefox, push run 30002550614), where this branch can't be responsible. Across the test-results DB it otherwise passes overwhelmingly: 1 fail / 192 msedge runs, 1 / 428 firefox, 0 on 440 chrome / 435 chromium / 439 webkit.

The diff is confined to browser cache-directory resolution — registry/index.ts, serverRegistry.ts, cli-client/registry.ts, browserFactory.ts — plus a new browsers-path.spec.ts. None of that is on the code path the DevTools request-details test asserts on.

Triaged by the Playwright bot - agent run

@Jobians

Copy link
Copy Markdown

Why this not updated in npm

Mert Can Altin (mertcanaltin) added a commit to mertcanaltin/playwright-cli that referenced this pull request Aug 23, 2026
`registry.defaultRegistryDirectory` became a function upstream in
microsoft/playwright#41942 and arrived here with the roll to
1.63.0-alpha-2026-08-05. `cacheFile()` still used it as a string, so
`path.join()` threw, `readCache()`/`writeCache()` swallowed the
TypeError, and the update check was never cached: every single CLI
invocation fetched the npm registry and re-ran the installed-skill
check.

Locally that is ~480ms per command instead of ~125ms.

Tests always set PLAYWRIGHT_CLI_INSTALLATION_FOR_TEST, so the default
branch was never exercised. Add a regression test that points HOME at a
temp directory and asserts the cache file is written.

Also hoist `cacheFile()` out of the try blocks so only I/O and parse
failures are swallowed there, instead of masking a path-computation bug
as "no cache".
Devin Rousso (dcrousso) pushed a commit to microsoft/playwright-cli that referenced this pull request Aug 24, 2026
…le (#454)

`registry.defaultRegistryDirectory` became a function upstream in
microsoft/playwright#41942 and arrived here with the roll to
1.63.0-alpha-2026-08-05. `cacheFile()` still used it as a string, so
`path.join()` threw, `readCache()`/`writeCache()` swallowed the
TypeError, and the update check was never cached: every single CLI
invocation fetched the npm registry and re-ran the installed-skill
check.

Locally that is ~480ms per command instead of ~125ms.

Tests always set PLAYWRIGHT_CLI_INSTALLATION_FOR_TEST, so the default
branch was never exercised. Add a regression test that points HOME at a
temp directory and asserts the cache file is written.

Also hoist `cacheFile()` out of the try blocks so only I/O and parse
failures are swallowed there, instead of masking a path-computation bug
as "no cache".
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Regression]: "PLAYWRIGHT_BROWSERS_PATH=0" no longer prevents evaluation of "defaultCacheDirectory" on Android/Termux

3 participants