question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

--open false as a cli arg does not prevent browser from opening

See original GitHub issue

⚠️ IMPORTANT ⚠️ Please do not ignore this template. If you do, your issue will be closed immediately.

Describe the bug

We are trying to use the cli argument --open false to prevent the browser from opening when starting up a server but it does not work. If we do add the config option in vite.config.ts it does work.

I tracked down the reason and this is due to a type mismatch when deciding whether to open the browser. Because the cli arg will always come through as a string ‘false’ will evaluate to truth in the block below.

if (options.open && !isRestart) {
  const path = typeof options.open === 'string' ? options.open : base;
  openBrowser(`${protocol}://${hostname}:${port}${path}`, true, server.config.logger);
}

My teammate and I did notice that depending on OS and browser default, the call in openBrowser will fail silently as well.

Reproduction

Any project that tries to use --open false as a cli arg.

System Info

  • vite version: 2.0.5
  • Operating System: OSx 10.15.7
  • Node version: v14.14.0
  • Package manager (npm/yarn/pnpm) and version: yarn v1.22.10

I am happy to open an MR if there is a specific direction to get this to work correctly. My first thought was just to check against ‘false’ if typeof options.open is a string and not even call openBrowser if that condition is met.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
drobannxcommented, Mar 22, 2021

@matias-capeletto - --no-open is perfect for our use case, we weren’t aware it was an option.

When we ran the vite --help command, we didn’t see --no-open but this works perfectly.

What are your thoughts on an MR to update the docs and/or change the --help output to show --no-open as an option and remove boolean as a type to --open

1reaction
Shinigami92commented, Mar 22, 2021

@drobannx Would love to see (and review) a docu update Could you create a PR for that? I think you don’t need to create an extra issue for that, we will jump directly into the PR 🙂

I will close this issue for now 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

Stop Visual Studio from launching a new browser window ...
For Visual Studio on Mac, the comparable settings is under "Project > Options > Run > Default > ASP.NET Core". Uncheck the "Open...
Read more >
List of Chromium Command Line Switches - Peter Beverloo
List of Chromium Command Line Switches. There are lots of command lines which can be used with the Google Chrome browser. Some change...
Read more >
Window.open() - Web APIs - MDN Web Docs
The open() method of the Window interface loads a specified resource into a new or existing browsing context (that is, a tab, a...
Read more >
Chromium Command Line Switches Cheat Sheet - Kapeli
Note that the browser process has no /prefetch:# argument; ... Prevents hosted apps from being opened in windows on Mac. --disable- ... Default...
Read more >
webbrowser — Convenient web-browser controller — Python ...
The script webbrowser can be used as a command-line interface for the module. ... If new is 0, the url is opened in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found