Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't open browser with 'o' shortcut when using --host option #13575

Closed
7 tasks done
mempf opened this issue Jun 21, 2023 · 2 comments · Fixed by #13579
Closed
7 tasks done

Can't open browser with 'o' shortcut when using --host option #13575

mempf opened this issue Jun 21, 2023 · 2 comments · Fixed by #13579
Labels
p2-nice-to-have Not breaking anything but nice to have (priority)

Comments

@mempf
Copy link

mempf commented Jun 21, 2023

Describe the bug

When using the Vite 4.4.0 branch/4.4.0-beta.0 release and setting the --host option the shortcut to open the browser with 'o' does not work and returns the following message instead:
No URL available to open in browser

VITE v4.4.0-beta.0  ready in 664 ms

  ➜  Network: http://192.168.0.100:5173/
  ➜  press h to show help
No URL available to open in browser

The same message occurs if the "open" option is used to attempt to open a browser automatically on startup.

It appears this issue started to occur after this commit and the issue goes away if reverted: 505f0b9

This issue seems to occur because when a --host is specified we no longer have a "local" address in the "resolvedUrls" used here:

const url = server.resolvedUrls?.local[0]

Perhaps simply looking at the "network" addresses for a resolvedUrl if the "local" list is empty is all that is needed:
const url = server.resolvedUrls?.local[0] ?? server.resolvedUrls?.network[0]

Reproduction

https://stackblitz.com/edit/vitejs-vite-ccink3?file=package.json&terminal=dev

Steps to reproduce

A minimal example has been included. T
o trigger the issue simply:

  1. Set the --host option to a value that is not localhost, 127.0.0.1 or 0.0.0.0. For example --host 192.168.0.100
  2. Press 'o' once vite opens
  3. Observe that the message "No URL available to open in browser" is display instead of the browser opening.

System Info

System:
    OS: Linux 5.15 Linux Mint 21.1 (Vera)
    Memory: 5.39 GB / 10.97 GB
    Container: Yes
    Shell: 5.1.16 - /bin/bash
  Binaries:
    Node: 16.20.0 - ~/.nvm/versions/node/v16.20.0/bin/node
    npm: 8.19.4 - ~/.nvm/versions/node/v16.20.0/bin/npm
  Browsers:
    Chrome: 114.0.5735.133
    Firefox: 114.0.2
  npmPackages:
    vite: ^4.4.0-beta.0 => 4.4.0-beta.0

Used Package Manager

npm

Logs

No response

Validations

@stackblitz
Copy link

stackblitz bot commented Jun 21, 2023

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

@bluwy
Copy link
Member

bluwy commented Jun 21, 2023

Perhaps simply looking at the "network" addresses for a resolvedUrl if the "local" list is empty is all that is needed:
const url = server.resolvedUrls?.local[0] ?? server.resolvedUrls?.network[0]

I think this make sense. Feel free to send a PR!

@bluwy bluwy added p2-nice-to-have Not breaking anything but nice to have (priority) and removed pending triage labels Jun 21, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Jul 6, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
p2-nice-to-have Not breaking anything but nice to have (priority)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants