Skip to content

Add --open-url flag to storybook dev#34671

Open
shubhamsns wants to merge 2 commits into
storybookjs:nextfrom
shubhamsns:feat/open-url-cli-flag
Open

Add --open-url flag to storybook dev#34671
shubhamsns wants to merge 2 commits into
storybookjs:nextfrom
shubhamsns:feat/open-url-cli-flag

Conversation

@shubhamsns
Copy link
Copy Markdown

@shubhamsns shubhamsns commented Apr 30, 2026

Summary

Adds support for a custom browser open URL in storybook dev, so users running a local HTTPS reverse proxy (e.g. portless) can have Storybook open the proxied URL instead of the default http://localhost:<port>.

  • Adds --open-url <url> CLI flag to storybook dev
  • Supports STORYBOOK_OPEN_URL env var as fallback (CLI flag takes precedence)
  • --no-open still disables opening entirely (takes precedence over --open-url)
  • When neither is set, behavior is unchanged

Closes #34669

Changes

  • code/core/src/types/modules/core-common.ts — Added openUrl?: string to CLIOptions
  • code/core/src/bin/core.ts — Added CLI flag + env var fallback
  • code/core/src/core-server/dev-server.ts — Use custom URL when opening browser
  • docs/api/cli-options.mdx — Documented the new flag

Test plan

  • Existing opener.test.ts tests pass (6/6)
  • Existing build-dev.onboarding.test.ts tests pass (4/4)
  • TypeScript check passes with no errors
  • Manual: storybook dev --open-url https://myapp.localhost opens the custom URL
  • Manual: STORYBOOK_OPEN_URL=https://myapp.localhost storybook dev opens the custom URL
  • Manual: storybook dev --no-open --open-url https://myapp.localhost does NOT open a browser

Disclosure

This PR was authored with AI assistance (Claude).

Summary by CodeRabbit

  • New Features

    • Added --open-url <url> CLI option to specify a custom URL when starting dev
    • Added STORYBOOK_OPEN_URL environment variable (CLI flag takes precedence)
    • --no-open disables automatic opening and overrides both --open-url and the env var
  • Bug Fixes

    • Opening failures now emit a warning only for custom URLs
  • Documentation

    • Updated CLI docs with usage and precedence details

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 30, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 1863fd04-6534-4dcb-af59-69591887e356

📥 Commits

Reviewing files that changed from the base of the PR and between 9e1d8ba and 76cc815.

📒 Files selected for processing (1)
  • code/core/src/core-server/dev-server.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • code/core/src/core-server/dev-server.ts

📝 Walkthrough

Walkthrough

Adds a new --open-url <url> CLI option and STORYBOOK_OPEN_URL env var fallback for storybook dev; extends CLIOptions with openUrl and updates dev-server logic to prefer the explicit URL when opening the browser while preserving previous fallback behavior.

Changes

Cohort / File(s) Summary
CLI and types
code/core/src/bin/core.ts, code/core/src/types/modules/core-common.ts
Add --open-url <url> CLI flag; read STORYBOOK_OPEN_URL when CLI flag absent; add openUrl?: string to CLIOptions.
Dev server / browser launch
code/core/src/core-server/dev-server.ts
Resolve target URL as options.openUrl ?? envUrl ?? defaultUrl; prefer options.openUrl when opening browser; only warn on open failures for custom URLs.
Documentation
docs/api/cli-options.mdx
Document --open-url <url>, STORYBOOK_OPEN_URL fallback, and precedence/interaction with --no-open.

Sequence Diagram(s)

sequenceDiagram
  participant CLI as CLI
  participant Dev as Dev Server
  participant Env as Env (STORYBOOK_OPEN_URL)
  participant Open as openInBrowser
  participant Browser as Browser

  CLI->>Dev: start (args may include --open-url)
  Dev->>Env: read STORYBOOK_OPEN_URL
  Dev->>Dev: targetUrl = options.openUrl ?? envUrl ?? defaultUrl
  Dev->>Open: open(targetUrl)
  Open->>Browser: attempt to open URL
  Browser-->>Open: success / error
  alt error and options.openUrl set
    Open-->>Dev: return error
    Dev->>Dev: log warning with URL and error
  end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs


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
Review rate limit: 6/8 reviews remaining, refill in 10 minutes and 22 seconds.

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

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
docs/api/cli-options.mdx (1)

56-56: ⚡ Quick win

Document --no-open precedence in this row too.

This row explains CLI vs env precedence, but not that --no-open disables opening entirely. Adding that here removes ambiguity for users scanning only this option.

Suggested doc tweak
-| `--open-url <url>`              | Open a custom URL instead of the default local address. Useful when running a local HTTPS reverse proxy. Can also be set via the `STORYBOOK_OPEN_URL` environment variable (CLI flag takes precedence).<br />`storybook dev --open-url https://myapp.localhost` |
+| `--open-url <url>`              | Open a custom URL instead of the default local address. Useful when running a local HTTPS reverse proxy. It can also be set via the `STORYBOOK_OPEN_URL` environment variable (CLI flag takes precedence). Ignored when `--no-open` is set.<br />`storybook dev --open-url https://myapp.localhost` |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@docs/api/cli-options.mdx` at line 56, Add clarification to the `--open-url
<url>` docs row: state that while the CLI flag `--open-url` takes precedence
over the `STORYBOOK_OPEN_URL` environment variable, the `--no-open` flag
disables opening entirely and will override both `--open-url` and the env var,
so users know `--no-open` wins when present; update the text for the `--open-url
<url>` entry to mention `--no-open` explicitly.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@code/core/src/core-server/dev-server.ts`:
- Around line 191-193: The current catch on openInBrowser(url) swallows all
errors; change it to emit a warning when the URL came from a user-provided
source (the --open-url option or STORYBOOK_OPEN_URL), so failures for custom
URLs are visible. In the catch block for openInBrowser(url) detect whether the
url was user-specified (check the flag/ENV used to set the url) and call the
project's logger (e.g., processLogger.warn) or console.warn with a short message
including the url and the caught error; keep swallowing the error for
default/open-internal cases but ensure custom URL failures produce a warning.

---

Nitpick comments:
In `@docs/api/cli-options.mdx`:
- Line 56: Add clarification to the `--open-url <url>` docs row: state that
while the CLI flag `--open-url` takes precedence over the `STORYBOOK_OPEN_URL`
environment variable, the `--no-open` flag disables opening entirely and will
override both `--open-url` and the env var, so users know `--no-open` wins when
present; update the text for the `--open-url <url>` entry to mention `--no-open`
explicitly.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 66d26d8c-4385-4c1d-bd26-50f86f7a2b60

📥 Commits

Reviewing files that changed from the base of the PR and between b516e85 and c2bce65.

📒 Files selected for processing (4)
  • code/core/src/bin/core.ts
  • code/core/src/core-server/dev-server.ts
  • code/core/src/types/modules/core-common.ts
  • docs/api/cli-options.mdx

Comment thread code/core/src/core-server/dev-server.ts Outdated
Adds a --open-url CLI flag (and STORYBOOK_OPEN_URL env var) to override
the URL opened in the browser during storybook dev. Warns when the
user-specified URL fails to open instead of silently swallowing the error.
@shubhamsns shubhamsns force-pushed the feat/open-url-cli-flag branch from c2bce65 to 9e1d8ba Compare April 30, 2026 12:16
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@docs/api/cli-options.mdx`:
- Line 56: The option description for `--open-url <url>` contains a sentence
fragment; revise the text so the fragment "Can also be set via the
`STORYBOOK_OPEN_URL` environment variable (CLI flag takes precedence)." is a
full sentence — e.g., change it to "It can also be set via the
`STORYBOOK_OPEN_URL` environment variable (the CLI flag takes precedence)."
Ensure the note about `--no-open` remains unchanged and keep references to
`--open-url <url>` and `STORYBOOK_OPEN_URL` intact.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 70bc7f37-c413-4676-a5a3-938a1f34ae15

📥 Commits

Reviewing files that changed from the base of the PR and between c2bce65 and 9e1d8ba.

📒 Files selected for processing (4)
  • code/core/src/bin/core.ts
  • code/core/src/core-server/dev-server.ts
  • code/core/src/types/modules/core-common.ts
  • docs/api/cli-options.mdx
🚧 Files skipped from review as they are similar to previous changes (1)
  • code/core/src/core-server/dev-server.ts

Comment thread docs/api/cli-options.mdx
| `--smoke-test` | Exit after successful start.<br />`storybook dev --smoke-test` |
| `--ci` | CI mode (skip interactive prompts, don't open browser).<br />`storybook dev --ci` |
| `--no-open` | Do not open Storybook automatically in the browser.<br />`storybook dev --no-open` |
| `--open-url <url>` | Open a custom URL instead of the default local address. Useful when running a local HTTPS reverse proxy. Can also be set via the `STORYBOOK_OPEN_URL` environment variable (CLI flag takes precedence). Note: `--no-open` disables opening entirely and overrides both `--open-url` and the environment variable.<br />`storybook dev --open-url https://myapp.localhost` |
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.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Fix sentence fragment in option description.

Line 56 has a fragment: “Can also be set via...”. Make it a complete sentence for docs clarity.

✏️ Suggested edit
-| `--open-url <url>`              | Open a custom URL instead of the default local address. Useful when running a local HTTPS reverse proxy. Can also be set via the `STORYBOOK_OPEN_URL` environment variable (CLI flag takes precedence). Note: `--no-open` disables opening entirely and overrides both `--open-url` and the environment variable.<br />`storybook dev --open-url https://myapp.localhost` |
+| `--open-url <url>`              | Open a custom URL instead of the default local address. Useful when running a local HTTPS reverse proxy. It can also be set via the `STORYBOOK_OPEN_URL` environment variable (CLI flag takes precedence). Note: `--no-open` disables opening entirely and overrides both `--open-url` and the environment variable.<br />`storybook dev --open-url https://myapp.localhost` |
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
| `--open-url <url>` | Open a custom URL instead of the default local address. Useful when running a local HTTPS reverse proxy. Can also be set via the `STORYBOOK_OPEN_URL` environment variable (CLI flag takes precedence). Note: `--no-open` disables opening entirely and overrides both `--open-url` and the environment variable.<br />`storybook dev --open-url https://myapp.localhost` |
| `--open-url <url>` | Open a custom URL instead of the default local address. Useful when running a local HTTPS reverse proxy. It can also be set via the `STORYBOOK_OPEN_URL` environment variable (CLI flag takes precedence). Note: `--no-open` disables opening entirely and overrides both `--open-url` and the environment variable.<br />`storybook dev --open-url https://myapp.localhost` |
🧰 Tools
🪛 LanguageTool

[style] ~56-~56: To form a complete sentence, be sure to include a subject.
Context: ...en running a local HTTPS reverse proxy. Can also be set via the `STORYBOOK_OPEN_URL...

(MISSING_IT_THERE)

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@docs/api/cli-options.mdx` at line 56, The option description for `--open-url
<url>` contains a sentence fragment; revise the text so the fragment "Can also
be set via the `STORYBOOK_OPEN_URL` environment variable (CLI flag takes
precedence)." is a full sentence — e.g., change it to "It can also be set via
the `STORYBOOK_OPEN_URL` environment variable (the CLI flag takes precedence)."
Ensure the note about `--no-open` remains unchanged and keep references to
`--open-url <url>` and `STORYBOOK_OPEN_URL` intact.

@shubhamsns
Copy link
Copy Markdown
Author

unsure about the logging comment by 🐇, i would personally prefer having a log

@shubhamsns
Copy link
Copy Markdown
Author

Also, I don't mean to create AI noise in the repo. Feel free to close this if it's adding noise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Empathy Queue (prioritized)

Development

Successfully merging this pull request may close these issues.

Support custom URL for browser auto-open (--open-url or env var)

2 participants