[wrangler] fix: show URL when browser cannot be opened in headless/container environments#14026
Conversation
…opened in headless environments On Linux systems without xdg-open installed (e.g. headless servers, Docker containers, Stackblitz), the `open` npm package rejects with ENOENT when trying to spawn the bundled xdg-open script. Previously this propagated to the generic ENOENT handler in handle-errors.ts, which printed a confusing "Missing file or directory: xdg-open" message with no actionable guidance. Now openInBrowser catches ENOENT errors (both from the open() promise rejection and from the child process error event) and logs a clear warning with the full URL so the user can proceed manually. Fixes cloudflare#14023
🦋 Changeset detectedLatest commit: c15cd29 The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
Codeowners approval required for this PR:
Show detailed file reviewers |
There was a problem hiding this comment.
Pull request overview
This PR improves Wrangler’s UX when attempting to open authentication/dev URLs in environments where a browser opener (notably xdg-open) is unavailable (e.g. containers/headless Linux). Instead of crashing with a generic ENOENT “missing file” message, Wrangler warns and prints the URL so the user can manually open it.
Changes:
- Add
ENOENThandling toopenInBrowser()so failures to spawn a browser opener don’t crash the CLI and instead print the URL. - Add a focused unit test suite covering success, ENOENT handling, and non-ENOENT error propagation.
- Add a changeset to ship the fix as a
wranglerpatch release.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| packages/wrangler/src/open-in-browser.ts | Catch ENOENT and emit a user-actionable warning that includes the URL (and debug logs the underlying error). |
| packages/wrangler/src/tests/open-in-browser.test.ts | Adds unit tests for open success, ENOENT fallback behavior, and non-ENOENT rethrowing. |
| .changeset/fix-open-in-browser-enoent-headless.md | Patch changeset documenting the improved behavior for headless/container environments. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
create-cloudflare
@cloudflare/deploy-helpers
@cloudflare/kv-asset-handler
miniflare
@cloudflare/pages-shared
@cloudflare/unenv-preset
@cloudflare/vite-plugin
@cloudflare/vitest-pool-workers
@cloudflare/workers-editor-shared
@cloudflare/workers-utils
wrangler
commit: |
…ack trace in debug log Address Copilot review feedback on PR cloudflare#14026.
…port type Fixes ESLint error: 'import() type annotations are forbidden'.
dario-piotrowicz
left a comment
There was a problem hiding this comment.
LGTM, thanks for the PR @matingathani 👍
workers-devprod
left a comment
There was a problem hiding this comment.
Codeowners reviews satisfied
Fixes #14023.
On Linux systems without
xdg-openinstalled (headless servers, Docker containers, StackBlitz), theopennpm package resolves the path to its bundledxdg-openscript relative to__dirname. When wrangler is bundled intowrangler-dist/cli.js,__dirnamepoints at the dist directory where the shell script doesn't exist, soopen()rejects with ENOENT. This error propagated to the generic ENOENT handler inhandle-errors.ts, which displayed a confusing "Missing file or directory: xdg-open" message with no actionable guidance.Fix:
openInBrowsernow catches ENOENT errors — both from theopen()promise rejection and from the child processerrorevent — and logs a clear warning with the full URL so users can copy-paste it into a browser manually.