Add auto-open browser on server start with -no-open flag - #16
Merged
Conversation
Co-authored-by: alexec <1142830+alexec@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add auto-open browser functionality to diff-server
Add auto-open browser on server start with -no-open flag
Aug 12, 2026
Co-authored-by: alexec <1142830+alexec@users.noreply.github.com>
alexec
approved these changes
Aug 12, 2026
alexec
marked this pull request as ready for review
August 12, 2026 20:58
alexec
enabled auto-merge (squash)
August 12, 2026 20:58
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds automatic browser launching when the diff-server HTTP server starts, with a CLI opt-out, to reduce manual copy/paste of the local URL after startup.
Changes:
- Bind the TCP port explicitly via
net.Listen, then serve viahttp.Serve. - Add a boolean flag intended to disable auto-opening the browser.
- Add
github.com/pkg/browser(and transitive deps) to open the URL cross-platform.
Reviewed changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| main.go | Adds port pre-bind, constructs localhost URL, and attempts to auto-open the browser unless disabled by a flag. |
| go.mod | Adds module requirements for github.com/pkg/browser and golang.org/x/sys. |
| go.sum | Adds checksums for the new dependencies. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| func main() { | ||
| port := flag.String("p", "3844", "Port to listen on") | ||
| workspaceDir := flag.String("C", ".", "Directory to scan for git repositories") | ||
| noBrowser := flag.Bool("B", false, "Disable auto-opening browser") |
Comment on lines
+35
to
44
| if !*noBrowser { | ||
| if err := browser.OpenURL(url); err != nil { | ||
| fmt.Fprintf(os.Stderr, "Failed to open browser: %v\n", err) | ||
| } | ||
| } | ||
|
|
||
| if err := http.Serve(listener, nil); err != nil { | ||
| fmt.Fprintf(os.Stderr, "Server failed: %v\n", err) | ||
| os.Exit(1) | ||
| } |
| go 1.24.4 | ||
|
|
||
| require ( | ||
| github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c // indirect |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Previously, users had to manually copy the URL and navigate to it after starting the server. This adds automatic browser opening on startup, cross-platform.
Changes
openBrowser(url)— dispatches toopen(macOS),xdg-open(Linux), orrundll32(Windows) viaos/exec-no-openflag — opt-out of auto-opennet.Listenbefore open — binds the port first so the server is accepting connections before the browser navigates to it; browser open errors are non-fatal (logged to stderr, server continues)