Skip to content

Core: Handle BROWSER=none correctly and improve error messages#33730

Merged
valentinpalkovic merged 1 commit intostorybookjs:nextfrom
jonathan-fulton:fix/browser-none-24191
Feb 3, 2026
Merged

Core: Handle BROWSER=none correctly and improve error messages#33730
valentinpalkovic merged 1 commit intostorybookjs:nextfrom
jonathan-fulton:fix/browser-none-24191

Conversation

@jonathan-fulton
Copy link
Copy Markdown
Contributor

@jonathan-fulton jonathan-fulton commented Jan 31, 2026

Description

Fixes #24191

When the BROWSER environment variable is set to none, Storybook should not attempt to open a browser. This fix ensures the behavior is correct and improves error messages.

Changes

  1. Properly handle openBrowser() return value: When openBrowser() returns false (indicating BROWSER=none was set intentionally), we now skip the fallback open() call entirely.

  2. Improved error messages: When browser opening fails, the error message now includes the current BROWSER environment variable value if set, helping users diagnose issues like typos or invalid values.

Before this fix

Even when openBrowser() returned false for BROWSER=none, the code might still attempt the fallback browser opening with the open package.

After this fix

# This now works correctly - no browser opens, no error
BROWSER=none npx storybook dev

# Invalid values now show helpful error messages
BROWSER=invalid npx storybook dev
# Error: Could not open http://localhost:6006 inside a browser...
# Note: BROWSER environment variable is set to "invalid". 
# To disable browser opening, use BROWSER=none or the --ci flag.

Testing

  • Tested with BROWSER=none - no browser opens, no error
  • Tested with invalid BROWSER values - error message includes the value

Summary by CodeRabbit

  • Bug Fixes
    • Improved error handling and messaging when browser fails to open.
    • Added support for BROWSER=none and --ci environment flags to prevent automatic browser opening.
    • Enhanced error messages with helpful guidance on controlling browser behavior.
    • Refined browser opening logic for more reliable execution.

✏️ Tip: You can customize this high-level summary in your review settings.

Fixes storybookjs#24191

When BROWSER environment variable is set to 'none', Storybook should not
attempt to open a browser. This fix:

1. Properly handles the return value of openBrowser() - when it returns
   false (BROWSER=none), we skip the fallback open() call entirely
2. Improves error messages when browser opening fails, showing the
   BROWSER env value if set to help users diagnose issues

Before this fix, even when openBrowser() returned false for BROWSER=none,
the code might still attempt the fallback browser opening.

The fix also helps users who set invalid BROWSER values by including the
current BROWSER value in the error message, making it easier to diagnose
issues like typos.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Jan 31, 2026

📝 Walkthrough

Walkthrough

This PR modifies the browser opening utility to handle cases where browser launching is explicitly disabled (BROWSER=none), adding an early return when the browser cannot open. It also corrects a variable name typo and improves error messages with environment variable guidance.

Changes

Cohort / File(s) Summary
Browser Opening Logic
code/core/src/core-server/utils/open-browser/open-in-browser.ts
Captures openBrowser result in new variable, adds early return when openBrowserResult is false, fixes typo (errorOccured→errorOccurred), enriches error messages with BROWSER environment hints (BROWSER=none or --ci).

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@valentinpalkovic valentinpalkovic self-assigned this Feb 2, 2026
@valentinpalkovic valentinpalkovic moved this to Empathy Queue (prioritized) in Core Team Projects Feb 2, 2026
@valentinpalkovic valentinpalkovic changed the title Fix: Handle BROWSER=none correctly and improve error messages Core: Handle BROWSER=none correctly and improve error messages Feb 2, 2026
@valentinpalkovic valentinpalkovic merged commit 71ed5ac into storybookjs:next Feb 3, 2026
119 of 124 checks passed
@github-project-automation github-project-automation bot moved this from Empathy Queue (prioritized) to Done in Core Team Projects Feb 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[Bug]: "NONE" Variable Not Interpreted as "no-open" flag and Lack of Warning/Error for Invalid Browser Variable

2 participants