fix: Windows support — Node.js server fallback for Playwright#194
Open
sozairali wants to merge 1 commit intogarrytan:mainfrom
Open
fix: Windows support — Node.js server fallback for Playwright#194sozairali wants to merge 1 commit intogarrytan:mainfrom
sozairali wants to merge 1 commit intogarrytan:mainfrom
Conversation
…nch Playwright Bun on Windows has broken subprocess pipe handling (oven-sh/bun#4253) and broken WebSocket client (oven-sh/bun#9911), which prevents Playwright from launching or connecting to Chromium. This makes /browse completely non-functional on Windows. On Windows, the CLI now spawns `node server-node.mjs` instead of `bun run server.ts`. The Node server bundle is transpiled from the same source with a Bun API polyfill (Bun.serve → http.createServer, Bun.spawnSync → child_process.spawnSync, etc.). macOS/Linux behavior is completely unchanged. Also fixes resolveServerScript() which excluded Windows paths (checked for startsWith('/') but Windows uses drive letters like C:\). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
/browseis completely non-functional on Windows due to two Bun bugs:child_process.spawnwithstdio: ["pipe"]broken on Windows (Playwright can't launch Chromium)connect()to a separately-launched Chromium either)node server-node.mjsinstead ofbun run server.ts. The Node server is transpiled from the same source with a Bun API polyfill (Bun.serve→http.createServer,Bun.spawnSync→child_process.spawnSync, etc.)resolveServerScript()which excluded Windows paths (startsWith('/')fails for drive letters likeC:\)What's included
browse/src/cli.tsnodeinstead ofbunresolveServerScript()usedstartsWith('/')to detect dev mode, which excluded Windows paths likeC:\....browse/src/bun-polyfill.cjsBun.serve,Bun.spawn,Bun.spawnSync,Bun.sleepfor NodeBun.serve(), etc.) since it's generated from the same source. Rather than maintaining a separate Node fork of the server, this shim lets the same code run on both runtimes. Written as.cjsso it can berequire()'d before the ESM server bundle executes. Only covers the 4 APIs the server actually uses — not a general-purpose Bun polyfill.browse/scripts/build-node-server.shserver-node.mjsfrom the same source as the Bun server. Usesbun build --target=nodefor transpilation, thensedto handle two things that can't be polyfilled at runtime:import.meta.dir(Bun-only, replaced with a__dirnameequivalent) andbun:sqlite(macOS-only cookie import, stubbed out since it's irrelevant on Windows). Runs as part ofbun run buildso the Node bundle stays in sync with the Bun binary.package.jsonbun run buildsetupensure_playwright_browserfunction tries to launch Chromium via Bun to verify it works — on Windows this hangs forever. Changed to use Node for the verification on Windows. Also added a Node.js requirement check with an actionable error message, since Node is now a runtime dependency on Windows.This is a workaround
When Bun fixes their Windows pipe/WebSocket handling, the entire Node fallback can be deleted — one
IS_WINDOWScheck removed and everything goes back to running on Bun everywhere.Test plan
Tested on Windows 11 (Git Bash, Bun 1.3.11, Node 22.16.0):
bun run dev goto https://example.com— navigates successfullybun run dev text— returns page contentbun run dev snapshot -i— returns interactive elements with @refsbun run dev fill @e1 "query"+click @e2— form interaction worksbun run dev console --errors— error monitoring worksbun run dev network— network log worksIS_WINDOWScode path taken)🤖 Generated with Claude Code