Skip to content

CLI: Respect BROWSER and BROWSER_ARGS#34513

Merged
Sidnioulz merged 12 commits into
storybookjs:nextfrom
ianzone:dev
May 22, 2026
Merged

CLI: Respect BROWSER and BROWSER_ARGS#34513
Sidnioulz merged 12 commits into
storybookjs:nextfrom
ianzone:dev

Conversation

@ianzone

@ianzone ianzone commented Apr 9, 2026

Copy link
Copy Markdown
Contributor

pass correct options to open()

Closes #30553

What I did

Checklist for Contributors

Testing

The changes in this PR are covered in the following automated tests:

  • stories
  • unit tests
  • integration tests
  • end-to-end tests

Manual testing

tested on my local machine.

Documentation

  • Add or update documentation reflecting your changes
  • If you are deprecating/removing a feature, make sure to update
    MIGRATION.MD

Checklist for Maintainers

  • When this PR is ready for testing, make sure to add ci:normal, ci:merged or ci:daily GH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found in code/lib/cli-storybook/src/sandbox-templates.ts

  • Make sure this PR contains one of the labels below:

    Available labels
    • bug: Internal changes that fixes incorrect behavior.
    • maintenance: User-facing maintenance tasks.
    • dependencies: Upgrading (sometimes downgrading) dependencies.
    • build: Internal-facing build tooling & test updates. Will not show up in release changelog.
    • cleanup: Minor cleanup style change. Will not show up in release changelog.
    • documentation: Documentation only changes. Will not show up in release changelog.
    • feature request: Introducing a new feature.
    • BREAKING CHANGE: Changes that break compatibility in some way with current major version.
    • other: Changes that don't fit in the above categories.

🦋 Canary release

This PR does not have a canary release associated. You can request a canary release of this pull request by mentioning the @storybookjs/core team here.

core team members can create a canary release here or locally with gh workflow run --repo storybookjs/storybook publish.yml --field pr=<PR_NUMBER>

Summary by CodeRabbit

  • Bug Fixes

    • Fixed handling of browser name and launch arguments so flags (e.g., --incognito) are passed reliably to the browser launcher.
    • Improved cross-platform fallback behavior to avoid incorrect coercion of browser launch options.
  • Tests

    • Updated tests to verify browser arguments are forwarded correctly when opening links.

Review Change Stack

pass correct option to open()
Copilot AI review requested due to automatic review settings April 9, 2026 14:57

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

Fixes Storybook’s browser-opening behavior so BROWSER/BROWSER_ARGS are passed through to the open() library correctly (closing #30553).

Changes:

  • Updates open() invocation to pass browser arguments via app: { name, arguments } instead of the legacy “array form”.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread code/core/src/core-server/utils/open-browser/opener.ts Outdated
@coderabbitai

coderabbitai Bot commented Apr 9, 2026

Copy link
Copy Markdown
Contributor

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

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: e64d3ef8-dc59-48cf-a384-638256a6cbb9

📥 Commits

Reviewing files that changed from the base of the PR and between e41be8c and 1591743.

📒 Files selected for processing (1)
  • code/core/src/core-server/utils/open-browser/opener.ts

📝 Walkthrough

Walkthrough

Replaced string+args coercion for browser launching: when browser is provided, open(url, options) now sets options.app = { name: browser, arguments: args }; otherwise options.app is left undefined. Tests updated to validate argument passing via app.arguments.

Changes

Browser Argument Handling

Layer / File(s) Summary
Imports and startBrowserProcess signature
code/core/src/core-server/utils/open-browser/opener.ts
Removed App type import and changed startBrowserProcess to accept `browser: string
options.app construction for open()
code/core/src/core-server/utils/open-browser/opener.ts
Constructs options.app = { name: browser, arguments: args } when browser is present; leaves app undefined otherwise; removed previous coercion into App[].
Call-site forwarding and action switch
code/core/src/core-server/utils/open-browser/opener.ts
openBrowser() no longer casts BROWSER to open App types; Actions.BROWSER now calls startBrowserProcess(value, url, args) directly.

Tests

Layer / File(s) Summary
Linux non-shell-script test update
code/core/src/core-server/utils/open-browser/opener.test.ts
Test sets process.env.BROWSER_ARGS and asserts open() is called with app: { name: 'google chrome', arguments: ['--incognito'] }, preserving wait: false and url: true.

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

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

@coderabbitai coderabbitai Bot 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.

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 `@code/core/src/core-server/utils/open-browser/opener.ts`:
- Line 192: The options object currently always sets app: { name: browser,
arguments: args } which produces an invalid shape when browser is undefined and
causes open() to reject silently; change the logic around the options
construction in opener.ts so that you only include the app property when browser
is a defined string (use browser and args to build app only when browser !=
null/undefined), otherwise create options without app (e.g., { wait:false,
url:true }); also ensure the open(url, options) rejection is not swallowed—catch
errors from open() and return false or propagate the error instead of always
returning true.
🪄 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: 7a4b2d6d-bfb5-4e4c-bca3-4549504073df

📥 Commits

Reviewing files that changed from the base of the PR and between aae6c95 and e3331f9.

📒 Files selected for processing (1)
  • code/core/src/core-server/utils/open-browser/opener.ts

Comment thread code/core/src/core-server/utils/open-browser/opener.ts Outdated

@coderabbitai coderabbitai Bot 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.

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 `@code/core/src/core-server/utils/open-browser/opener.ts`:
- Around line 192-196: Add a regression test in
code/core/src/core-server/utils/open-browser/opener.test.ts that exercises the
new BROWSER_ARGS path: set up the environment (or pass values) so the code path
that constructs the options object in opener.ts runs with a non-empty args
value, call the function that builds the options (the same entry used by
existing tests around lines 97-109), and assert that the returned options.app is
an object with name equal to the provided browser and arguments equal to the
expected args array/string; also include a test case for when browser is truthy
but no args are provided to ensure arguments is undefined or handled as before.
Ensure the test cleans up environment changes so it won’t affect other tests.
🪄 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: 9036eee4-c550-4123-8fd6-7771db87d349

📥 Commits

Reviewing files that changed from the base of the PR and between e3331f9 and f82ea0b.

📒 Files selected for processing (1)
  • code/core/src/core-server/utils/open-browser/opener.ts

Comment thread code/core/src/core-server/utils/open-browser/opener.ts

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

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread code/core/src/core-server/utils/open-browser/opener.ts Outdated
Comment thread code/core/src/core-server/utils/open-browser/opener.ts Outdated
@ianzone ianzone changed the title bug: BROWSER and BROWSER_ARGS env are not respected fix: respect BROWSER and BROWSER_ARGS May 22, 2026
@ianzone ianzone changed the title fix: respect BROWSER and BROWSER_ARGS Fix: Respect BROWSER and BROWSER_ARGS May 22, 2026
@Sidnioulz Sidnioulz added ci:normal Run our default set of CI jobs (choose this for most PRs). cli feature request and removed bug labels May 22, 2026
@Sidnioulz Sidnioulz changed the title Fix: Respect BROWSER and BROWSER_ARGS CLI: Respect BROWSER and BROWSER_ARGS May 22, 2026
@Sidnioulz Sidnioulz self-assigned this May 22, 2026
@Sidnioulz Sidnioulz self-requested a review May 22, 2026 13:01

@Sidnioulz Sidnioulz 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.

Tested locally, the fix works well! Thanks @ianzone!

Could you please include a new paragraph in https://storybook.js.org/docs/configure/environment-variables#using-environment-variables-to-choose-the-browser to explain that BROWSER_ARGS can be used to adjust params (but requires BROWSER to be set to)? I'll see if Copilot is in the mood to do it for you but no promises.

Also, FYI: the "manual testing" section should explain how I, as a reviewer, can test your PR. It shouldn't explain how you tested as a PR author. The goal is to help reviewers save time by jumping into review faster :)

@Sidnioulz Sidnioulz 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.

I've added the docs. Let's wait for CI and I'll merge if it's green. Thanks again!

@Sidnioulz Sidnioulz merged commit c22b930 into storybookjs:next May 22, 2026
106 checks passed
@github-project-automation github-project-automation Bot moved this from Empathy Queue (prioritized) to Done in Core Team Projects May 22, 2026
@github-actions github-actions Bot mentioned this pull request May 22, 2026
22 tasks
@ianzone ianzone deleted the dev branch May 22, 2026 14:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci:normal Run our default set of CI jobs (choose this for most PRs). cli core feature request

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[Bug]: BROWSER and BROWSER_ARGS env doesn't work

5 participants