Skip to content

Feature Request: Add 'open' as an option.  #28

Description

@dwkns

The previous BrowserSync dev server had an open: true option that would open the browser window when the server started.

Would be nice to have that added back in. This horrible hack (nearly) works:

// server.js
const DEFAULT_OPTIONS = {
...
 open: false,           // Open URL in browser on launch.
...

and

// server.js → get server()
...
this._server.on("listening", (e) => {
  this.setupReloadNotifier();
  let { port } = this._server.address();

  let hostsStr = "";
  if(this.options.showAllHosts) {
    // TODO what happens when the cert doesn’t cover non-localhost hosts?
    let hosts = devip().map(host => `${this._serverProtocol}//${host}:${port}${this.options.pathPrefix} or`);
    hostsStr = hosts.join(" ") + " ";
  }

  this.logger.info(`Server at ${hostsStr}${this._serverProtocol}//localhost:${port}${this.options.pathPrefix}${this.options.showVersion ? ` (v${pkg.version})` : ""}`);

  if(this.options.open) {
    this.logger.info(`Opening in browser...`);
    require('out-url').open(`${hostsStr}${this._serverProtocol}//localhost:${port}${this.options.pathPrefix}`);
  }

});


return this._server;
...

But adds a dependency and if you change the open option from true to false in .eleventy.js while the server is running it opens the browser again. I'm sure there is a much better way to do this.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestneeds-votesA feature request on the backlog that needs upvotes or downvotes. Remove this label when resolved.

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions