Skip to content

bug: BROWSER and BROWSER_ARGS env are not respected#34513

Open
ianzone wants to merge 4 commits intostorybookjs:nextfrom
ianzone:dev
Open

bug: BROWSER and BROWSER_ARGS env are not respected#34513
ianzone wants to merge 4 commits intostorybookjs:nextfrom
ianzone:dev

Conversation

@ianzone
Copy link
Copy Markdown

@ianzone ianzone commented Apr 9, 2026

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

Caution

This section is mandatory for all contributions. If you believe no manual test is necessary, please state so explicitly. Thanks!

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 when opening links; arguments are now passed consistently to the browser launcher.
    • Improved fallback behavior for building browser launch options to avoid incorrect coercion and ensure links open with the intended parameters (e.g., argument flags are preserved).

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

Copilot AI left a comment

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.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 9, 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: f3a60fe0-b864-46dd-afa4-bd1c2f23e092

📥 Commits

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

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

📝 Walkthrough

Walkthrough

Replaced legacy string-to-array coercion for browser + args; open(url, options) now sets options.app to { name: browser, arguments: args } when browser is truthy, otherwise options.app is undefined. Tests updated to assert argument passing via app.arguments.

Changes

Cohort / File(s) Summary
Browser Argument Handling
code/core/src/core-server/utils/open-browser/opener.ts
Removed logic that coerced a string browser plus args into an App[]. Fallback open() now uses options.app = { name: browser, arguments: args } when browser is provided, or undefined when not.
Tests
code/core/src/core-server/utils/open-browser/opener.test.ts
Updated Linux non-shell-script test to set process.env.BROWSER_ARGS and assert open() is called with app: { name: 'google chrome', arguments: ['--incognito'] } instead of a string app.

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.

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 `@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

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 `@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

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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.

const options = {
app: browser ? { name: browser, arguments: args } : undefined,
wait: false,
url: true
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

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

Formatting in the new options object is inconsistent with surrounding code (missing trailing comma after url: true and missing comma in the closing brace block). With the repo formatter config (.oxfmtrc.json sets trailingComma: "es5") and existing style in this file (e.g. { stdio: 'inherit', }), this is likely to be auto-reformatted or fail lint/format checks.

Suggested change
url: true
url: true,

Copilot uses AI. Check for mistakes.
Comment on lines 191 to +195
try {
const options = { app: browser, wait: false, url: true };
const options = {
app: browser ? { name: browser, arguments: args } : undefined,
wait: false,
url: true
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

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

browserTarget originates from process.env.BROWSER (a string | undefined), but it’s cast to App | readonly App[] and then used to build { name: browser, arguments: args }. This wider typing obscures the actual contract and makes it easy to accidentally pass an App object/array as the name. Consider narrowing startBrowserProcess/browserTarget to string | undefined (and keep app construction strictly in terms of a browser name), which will also avoid needing type assertions here.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

@copilot apply changes based on this feedback

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants