Fix browser opening on WSL2 with centralized browser package#91
Open
rodmhgl wants to merge 5 commits intoiximiuz:mainfrom
Open
Fix browser opening on WSL2 with centralized browser package#91rodmhgl wants to merge 5 commits intoiximiuz:mainfrom
rodmhgl wants to merge 5 commits intoiximiuz:mainfrom
Conversation
Pass explicit "%s" format specifier in NewStatusError calls where err.Error() was used directly as the format string, which go vet flags as unsafe if the error message contains printf verbs.
On WSL2, xdg-open fails to open the Windows browser, breaking the auth login flow and all other URL-opening commands. This adds a centralized browser package that detects WSL via /proc/version and tries wslview, cmd.exe, then xdg-open as fallbacks. The fallback message now prominently displays the URL on its own line for easy copying. Replaces duplicated open.Run + fallback pattern across 9 call sites.
There was a problem hiding this comment.
Pull request overview
This PR centralizes and improves URL browser-opening behavior (especially on WSL2) by introducing a dedicated internal/browser package and updating all CLI call sites to use a consistent open+fallback UX.
Changes:
- Add
internal/browserwith WSL detection and a WSL-specific opener chain (wslview→cmd.exe /c start→open-golangfallback). - Replace duplicated “open browser + fallback message” logic across commands with
browser.OpenWithFallbackMessage. - Fix
go vetwarnings by switchingNewStatusErrorcall sites to use constant format strings.
Reviewed changes
Copilot reviewed 13 out of 14 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| internal/labcli/cliutil.go | Fix go vet format-string warnings in WrapStatusError. |
| internal/browser/browser.go | New browser-opening helper with WSL detection and unified fallback messaging. |
| internal/browser/browser_test.go | Add unit tests for WSL detection and fallback message formatting. |
| cmd/auth/login.go | Use centralized browser open + improved fallback UX for auth login. |
| cmd/challenge/start.go | Use centralized browser open + fallback message. |
| cmd/content/create.go | Use centralized browser open + fallback message after content creation. |
| cmd/course/start.go | Use centralized browser open + fallback message for lesson start. |
| cmd/expose/port.go | Use centralized browser open + fallback message for exposed ports. |
| cmd/expose/shell.go | Use centralized browser open + fallback message for exposed shell sessions. |
| cmd/playground/restart.go | Use centralized browser open + fallback message for restarts. |
| cmd/playground/start.go | Use centralized browser open + fallback message for playground start. |
| cmd/playground/tasks.go | Fix go vet format-string warning in NewStatusError. |
| cmd/tutorial/start.go | Use centralized browser open + fallback message for tutorial start. |
| go.sum | Dependency checksum updates due to module graph changes. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
tryExec previously used cmd.Start() which only checks if the process launched, not if it succeeded. If wslview or cmd.exe started but exited non-zero, Open() would return nil and the user would never see the fallback URL message. Using cmd.Run() waits for exit and checks status, ensuring the fallback chain works correctly.
URLs commonly contain & for query parameters, which cmd.exe interprets as a command separator. Without quoting, 'start "" https://example.com?a=1&b=2' would execute 'start "" https://example.com?a=1' and then 'b=2' as a separate command. Wrapping the URL in double quotes prevents this.
Add a package-level openFunc variable that OpenWithFallbackMessage uses instead of calling Open directly. Tests swap in a stub via stubOpen(), enabling deterministic assertions for both the success path (no fallback printed) and failure path (fallback URL displayed) without launching any external processes.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 13 out of 14 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Summary
internal/browser/package that detects WSL (via/proc/version) and useswslview→cmd.exe /c start→xdg-openfallback chain to open the Windows browseropen.Run+ fallback pattern across all 9 call sites withbrowser.OpenWithFallbackMessage()go vetwarnings for non-constant format strings inNewStatusErrorcallsResolves #90
Motivation
On WSL2,
xdg-open(used byopen-golang) fails to open the Windows browser. This breaks the UX forlabctl auth loginand all other commands that open URLs the user sees a generic "Couldn't open the browser" message with no easy way to copy the URL. On manually copying the URL to login through the browser in Windows, the callback never makes it back to the CLI in WSL2 and hangs.This also unblocks the other workflows that open URLs (such as
challenge start) on WSL2.Before:
After:
Browser flow successful
Unable to open browser
Test plan
go build ./...compiles cleanlygo test ./...all tests pass (including new internal/browser/ tests)go vet ./...no warnings