Skip to content

[wrangler] fix: show URL when browser cannot be opened in headless/container environments#14026

Merged
dario-piotrowicz merged 5 commits into
cloudflare:mainfrom
matingathani:fix/open-in-browser-enoent-headless
May 28, 2026
Merged

[wrangler] fix: show URL when browser cannot be opened in headless/container environments#14026
dario-piotrowicz merged 5 commits into
cloudflare:mainfrom
matingathani:fix/open-in-browser-enoent-headless

Conversation

@matingathani

Copy link
Copy Markdown
Contributor

Fixes #14023.

On Linux systems without xdg-open installed (headless servers, Docker containers, StackBlitz), the open npm package resolves the path to its bundled xdg-open script relative to __dirname. When wrangler is bundled into wrangler-dist/cli.js, __dirname points at the dist directory where the shell script doesn't exist, so open() rejects with ENOENT. This error propagated to the generic ENOENT handler in handle-errors.ts, which displayed a confusing "Missing file or directory: xdg-open" message with no actionable guidance.

Fix: openInBrowser now 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 users can copy-paste it into a browser manually.

⚠ [WARNING] Failed to open a browser automatically. You may need to install `xdg-utils`
  (e.g. `apt install xdg-utils`) or set a default browser.
  Please visit the following URL in your browser:
  https://dash.cloudflare.com/oauth2/auth?...

  • Tests
    • Tests included/updated
  • Public documentation
    • Documentation not necessary because: the fix is a UX improvement for an edge case — no new config options or commands added

…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
Copilot AI review requested due to automatic review settings May 23, 2026 19:41
@changeset-bot

changeset-bot Bot commented May 23, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: c15cd29

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
wrangler Patch
@cloudflare/vite-plugin Patch
@cloudflare/vitest-pool-workers Patch

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

@github-project-automation github-project-automation Bot moved this to Untriaged in workers-sdk May 23, 2026
@workers-devprod workers-devprod requested review from a team and NuroDev and removed request for a team May 23, 2026 19:41
@workers-devprod

workers-devprod commented May 23, 2026

Copy link
Copy Markdown
Contributor

Codeowners approval required for this PR:

  • ✅ @cloudflare/wrangler
Show detailed file reviewers

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 ENOENT handling to openInBrowser() 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 wrangler patch 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.

Comment thread packages/wrangler/src/open-in-browser.ts
Comment thread packages/wrangler/src/open-in-browser.ts Outdated
@pkg-pr-new

pkg-pr-new Bot commented May 23, 2026

Copy link
Copy Markdown
create-cloudflare

npm i https://pkg.pr.new/create-cloudflare@14026

@cloudflare/deploy-helpers

npm i https://pkg.pr.new/@cloudflare/deploy-helpers@14026

@cloudflare/kv-asset-handler

npm i https://pkg.pr.new/@cloudflare/kv-asset-handler@14026

miniflare

npm i https://pkg.pr.new/miniflare@14026

@cloudflare/pages-shared

npm i https://pkg.pr.new/@cloudflare/pages-shared@14026

@cloudflare/unenv-preset

npm i https://pkg.pr.new/@cloudflare/unenv-preset@14026

@cloudflare/vite-plugin

npm i https://pkg.pr.new/@cloudflare/vite-plugin@14026

@cloudflare/vitest-pool-workers

npm i https://pkg.pr.new/@cloudflare/vitest-pool-workers@14026

@cloudflare/workers-editor-shared

npm i https://pkg.pr.new/@cloudflare/workers-editor-shared@14026

@cloudflare/workers-utils

npm i https://pkg.pr.new/@cloudflare/workers-utils@14026

wrangler

npm i https://pkg.pr.new/wrangler@14026

commit: c15cd29

@dario-piotrowicz dario-piotrowicz left a comment

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.

LGTM, thanks for the PR @matingathani 👍

@workers-devprod workers-devprod left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Codeowners reviews satisfied

@github-project-automation github-project-automation Bot moved this from Untriaged to Approved in workers-sdk May 27, 2026
@dario-piotrowicz dario-piotrowicz merged commit 66d86ba into cloudflare:main May 28, 2026
54 checks passed
@github-project-automation github-project-automation Bot moved this from Approved to Done in workers-sdk May 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Missing file or directory: xdg-open

4 participants