Skip to content

fix: Playwright detection failing in prebuilt release binaries - #332

Merged
kamilcast merged 3 commits into
masterfrom
fix-absolute-playwright-paths-included-in-the-binary
May 21, 2026
Merged

kamilcast merged 3 commits into
masterfrom
fix-absolute-playwright-paths-included-in-the-binary

Conversation

@kamilcast

@kamilcast kamilcast commented May 21, 2026 •

Copy link
Copy Markdown
Contributor

Fix Playwright detection failing in prebuilt release binaries

Problem

When installing kimchi from prebuilt release artifacts (curl -fsSL .../install.sh | bash), Playwright is never detected — users always see the fallback warning:

Playwright is not installed. Fetching with native HTTP client — JavaScript-rendered content (SPAs) will not be captured. Run npx playwright install chromium to enable full SPA support.

Installing locally via pnpm run build:binary && pnpm run install:local works fine.

Root Cause

When Bun compiles the binary with bun build --compile, it converts relative require.resolve() calls inside bundled dependencies into absolute paths from the build machine.

In playwright-core/lib/server/utils/nodePlatform.js, the line:

const coreDir = path.dirname(require.resolve("../../../package.json"));

gets compiled to:

var coreDir = path.dirname(require.resolve("/Users/runner/work/kimchi/kimchi/node_modules/.pnpm/playwright-core@1.59.1/..."));

This require.resolve() runs at module initialization time (top-level const). On any machine other than the build machine, this path doesn't exist, so require.resolve throws, the entire playwright-core module fails to initialize, and the error propagates up through loadPlaywright() → playwrightAvailable = false → fallback warning.

Local build works because the hardcoded path points to the developer's own node_modules which still exist on the same machine. Release build fails because the path points to the CI runner's filesystem (/Users/runner/work/kimchi/kimchi/...).

Fix

Added a pnpm patch for playwright-core@1.59.1 that wraps the coreDir initialization in a try-catch. coreDir is only used for stack-trace filtering (hiding playwright internals from error traces), so an empty string fallback is functionally safe.

Patch removal criteria

This patch can be removed when either:

  • Bun fixes require.resolve in compiled binaries — Bun PR #29066 fixed __dirname/__filename but require.resolve() with relative paths still gets hardcoded.
  • Playwright upstream wraps this in a try-catch themselves.

Kimchi Summary

What changed

Patches playwright-core to prevent runtime MODULE_NOT_FOUND errors in Bun compiled binaries by falling back to __dirname-based path resolution when require.resolve() fails.

Why

Bun compiles relative require.resolve() calls into absolute build-machine paths that are invalid at runtime. This causes playwright-core to crash when locating its package root inside a compiled binary.

Key changes

  • patches/playwright-core@1.59.1.patch: Wraps require.resolve("../../../package.json") in lib/server/utils/nodePlatform.js with a try-catch block and falls back to path.resolve(__dirname, "../../..") on MODULE_NOT_FOUND.
  • package.json: Registered playwright-core@1.59.1 under patchedDependencies.
  • pnpm-lock.yaml: Updated playwright-core snapshots to apply the new patch hash.

Impact

  • Enables playwright-core to function correctly when bundled in Bun compiled binaries.
  • Existing non-compiled environments are unaffected because the fallback only triggers on missing modules.

@readme-ai-writer

readme-ai-writer Bot commented May 21, 2026 •

Copy link
Copy Markdown

📚 No documentation changes were needed for this PR (Job ID: 6a0f105b3d9f8936519541fd).

@kimchi-review

kimchi-review Bot commented May 21, 2026 •

Copy link
Copy Markdown

Kimchi Code Review

Property Value
Commit 76c9a48
Author @kamilcast
Files changed 0
Review status Completed
Comments 2 (1 info, 1 warning)
Duration 120s

Summary

📊 Review Score: 82/100 (overall code quality — 0 lowest, 100 highest)
⏱️ Estimated effort to review: 1/5 (1 = trivial, 5 = very complex)

🧪 Tests: no — No tests were added or modified to verify the patched Playwright behavior in Bun compiled binaries or to guard against regressions in stack-trace filtering.

📝 Found 2 issue(s). See inline comments for details.

What to expect

Kimchi will analyze the changes in this pull request and post:

  • A summary of the overall changes
  • Inline comments on specific lines with findings categorized by issue type

The review typically completes within a few minutes. This comment will be updated once the review is ready.

Interact with Kimchi
  • @kimchi review — re-trigger a full review on the latest commit
  • @kimchi summary — regenerate the PR summary
  • @kimchi ignore — skip this PR (no review will be posted)
  • Reply to any inline comment to ask follow-up questions or request clarification
Configuration

Reviews are configured by your organization admin.
Review instructions, excluded directories, and severity thresholds can be adjusted per repository in the Kimchi dashboard.


Powered by Kimchi — AI-powered code review by CAST AI

@kimchi-review kimchi-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

📊 Review Score: 82/100 (overall code quality — 0 lowest, 100 highest)
⏱️ Estimated effort to review: 1/5 (1 = trivial, 5 = very complex)

🧪 Tests: no — No tests were added or modified to verify the patched Playwright behavior in Bun compiled binaries or to guard against regressions in stack-trace filtering.

📝 Found 2 issue(s). See inline comments for details.

Comment thread patches/playwright-core@1.59.1.patch Resolved
Comment thread patches/playwright-core@1.59.1.patch Resolved
Comment thread patches/playwright-core@1.59.1.patch Resolved
Address review feedback:
- Narrow bare catch to only handle MODULE_NOT_FOUND, re-throw
  unexpected errors (corrupt installs, permission errors)
- Replace TODO placeholder with actual upstream link:
  oven-sh/bun#29066
@kamilcast
kamilcast merged commit 7b75233 into master May 21, 2026
2 checks passed
@mszostok
mszostok deleted the fix-absolute-playwright-paths-included-in-the-binary branch September 23, 2026 08:05
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.

2 participants