Browser-sync: Open browser to a custom URL

Created on 6 Apr 2015  路  9Comments  路  Source: BrowserSync/browser-sync

Hi,
I'd like to automatically open the browser to a specific URL like my-project.com:3000, and not to localhost:3000.
I can't do it with tunnel option. Is it possible?

Most helpful comment

in the hopes of saving someone else some time later:

  browserSync.init({
    server: {
      baseDir: '/baseDir/Path',
      index: 'index.html',
    },
    startPath: `index.html?query=something`
  });

All 9 comments

The open option is for auto-opening one of the BrowserSync URLs.

If you need a specific URL, just set open: false and perform that action yourself with something like the opn module :)

Hey! Sorry for necromancing this post, but does open work to open custom URLs as stated in the Command Line Documentation?

Choose which URL is auto-opened (local, external or tunnel), or provide a url

I've tried following command: browser-sync start --proxy "10.0.1.166:8080" --files "WebClients" --open "http://some-custom-url"

I have a similar question...
How do you specify an specic page when you init your Gulp project?

startPath seems to get mentioned in the docs, however it doesnt work for me:

gulp.task('browser-sync',  >() {
    browserSync.init({
      server: {
        baseDir: "./public",
        startPath: 'index.html#test'                                                                                                                                                                                               
      }
    })
})

UPDATE: this seems to do the job:

    browserSync.init({
      server: {
        baseDir: "./web",
        middleware: [{
          route: "/",
          handle: > (req, res, next) {
            res.writeHead(302,  { 'Location': '/index.html#test' })                                                                                                                                                                
            res.end()
            next()
          }
        }]
      }
    })

@coderofsalvation The startPath is a sibling option of server, not a child

@dangelion This seems to work for me { "host": "my-project.com", "open": "external", "port": 3000 }

in the hopes of saving someone else some time later:

  browserSync.init({
    server: {
      baseDir: '/baseDir/Path',
      index: 'index.html',
    },
    startPath: `index.html?query=something`
  });

@ctcpip
Such a joy to have someone actually comprehend _and_ answer a question. Thank you!

@ctcpip Thank you!

Just another example -
browserSync.init({ server: "./dist", startPath: '/en/index.html', });

Was this page helpful?
0 / 5 - 0 ratings

Related issues

npearson72 picture npearson72  路  3Comments

ronilaukkarinen picture ronilaukkarinen  路  4Comments

jitendravyas picture jitendravyas  路  4Comments

Zver64 picture Zver64  路  3Comments

sedubois picture sedubois  路  3Comments