BrowserSync / browser-sync

Keep multiple browsers & devices in sync when building websites. https://browsersync.io
https://discord.gg/2d2xUThp
Apache License 2.0
12.17k stars 755 forks source link

browser-sync start `--open` does not work with URL #1982

Open xgqfrms opened 1 year ago

xgqfrms commented 1 year ago

Issue details

browser-sync start --open does not work with URL

# Choose which URL is auto-opened (local, external or tunnel), or provide a url
$ browser-sync start --open 'http://localhost:3000/public/index.html' --server --files './**/*.*'

https://browsersync.io/docs/command-line

Steps to reproduce/test case

  1. create a new node.js project, with a public folder and index.html file
  2. run npm script
# Choose which URL is auto-opened (local, external or tunnel), or provide a url
$ browser-sync start --open 'http://localhost:3000/public/index.html' --server --files './**/*.*'

opened http://localhost:3000/

wanted http://localhost:3000/public/index.html

image

image

Please specify which version of Browsersync, node and npm you're running


$ browser-sync --version
# 2.26.7

$ node -v
# v18.12.0

$ npm -v
# 8.19.2

Affected platforms

Browsersync use-case

If CLI, please paste the entire command below

# Choose which URL is auto-opened (local, external or tunnel), or provide a url
$ browser-sync start --open 'http://localhost:3000/public/index.html' --server --files './**/*.*'
trusktr commented 1 year ago

I noticed this too. Instead, I got it working with --startPath. For example, I think what you were trying to do is equivalent to this:

browser-sync . --startPath=/public/index.html --watch

then it automatically opens the browser to http://localhost:3000/public/index.html.

shakyShane commented 1 year ago

thanks @trusktr, that's correct.

Agree with the original post too though - this should 'just work' with --open

shakyShane commented 1 year ago

also side note, that command in the original post could probably be shorted to

# before
browser-sync start --open 'http://localhost:3000/public/index.html' --server --files './**/*.*'

# after
browser-syn public -w