Feature Request: Add 'open' as an option.
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 58/100
- Issue type
- Feature
- Clarity
- Mostly clear
- Activity status
- Quiet
- Tech stack
- javascript
- Domain
- devtools
Research direction
Start in server.js, especially the DEFAULT_OPTIONS definition and the get server() listening handler shown in the issue. Trace how server options are updated while the server runs and determine how the browser should open only when startup requires it. Done means an open option is supported without adding an unnecessary dependency or reopening the browser after the option changes.
Written by the indexing model from the issue text.
Description
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.
- Dominant language
- JavaScript
- Stars
- 109
- Forks
- 20
- Avg merge
- 1m
- Merged PRs (30d)
- 1
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from 11ty/dev-server
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
11ty/dev-server#152 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
11ty/dev-server#150 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
11ty/dev-server#147 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
11ty/dev-server#128 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
11ty/dev-server#95 ·
Similar issues
-
curation good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
amponce/archive-movie-browser#186 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
clerk/javascript#9852 ·
-
bug p1 tools
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
HarperFast/skills#96 ·
-
factory-active factory-automatic task-bug-reproduction-cannot-reproduce task-identify-harness-labels-done task-identify-issue-type-done
Difficulty 2/5 1-3 hours Newbie friendliness 84/100