xiaobaifly7: on Windows, signing in to Cloudflare's MCP server (and any
sign-in) opened no browser, and the window said to finish in the
browser until the sign-in timed out. Wails' Browser.OpenURL starts
rundll32 by its bare name, which Go looks up with PATHEXT's extensions;
a PATHEXT without .EXE (WSL passes one on as ".CPL") finds nothing, and
host.OpenURL dropped the error.
- proc.OpenBrowser starts %SystemRoot%\System32\rundll32.exe by its
path (open / xdg-open / termux-open-url elsewhere) and returns the
launcher's error. host.OpenURL falls back to it when Wails' fails, and
the CLI's account sign-in uses it.
- Windows.OpenURL returns the error. /api/signin, the plugin sign-in and
/api/library/mcp-signin answer it as openError; /api/open fails with
it, so Open again says why.
- The sign-in card shows "magpie couldn't open your browser: {error}.
Open the sign-in link below in a browser yourself." where it said
magpie opened the page, with the link already shown below; the MCP
editor shows the error with the link and a copy button. Translated
(zh, zh-TW, ja, de).
- Open again matched its sign-in by identity, so a poll that put a fresh
copy of the same sign-in in place kept the old error after a
successful retry; it now matches by id.
Run:
- TestBrowserNamesRundll32ByItsPath, TestMCPSignInSaysTheBrowserDidntOpen
and the /api/open and /api/signin tests in signin_open_2043_test.go.
Broken by hand: the bare name back in browserCommand fails the first;
openError returning "" fails the gui tests.
- On the Windows box (amd64, cmd with PATHEXT=.CPL): exec.Command
("rundll32", ...).Start() gave `exec: "rundll32": executable file not
found in %PATH%`; proc.OpenBrowser started it (nil). The proc test
binary's TestBrowserNamesRundll32ByItsPath passed there.
- signin-browser-down.test.cjs (new): the card's text, the link, no
sideways overflow, Open again failing then succeeding, and the MCP
editor's error and link, in Chromium and WebKit at 1100 and 420 in
every language: 20/20. The related sign-in GUI tests: 451/452, the
one a signin-proxy flake also on main (fixed in its own commit).
- gofmt -l clean; go vet darwin, linux -tags nogui, windows; GOOS=linux
and windows builds; go test -tags nogui ./internal/gui/
./internal/proc/ ./internal/cli/.
Not tried: the real Wails app on Windows under PATHEXT=.CPL (the
fallback path is exercised only through proc.OpenBrowser), WSL itself,
the reporter's machine. Not covered: internal/tui/sessions.go and
internal/provider/install.go start `powershell` by its bare name, which
would miss the same way under such a PATHEXT.
48 lines
1.4 KiB
Go
48 lines
1.4 KiB
Go
package proc
|
|
|
|
import (
|
|
"os"
|
|
"os/exec"
|
|
"path/filepath"
|
|
"runtime"
|
|
)
|
|
|
|
// OpenBrowser opens url in the user's default browser. The error is the
|
|
// launcher's failing to start, for the caller to show with the link to open
|
|
// by hand: a sign-in that waits on a page that never opened only times out
|
|
// (#2043).
|
|
func OpenBrowser(url string) error {
|
|
name, args := browserCommand(runtime.GOOS, os.Getenv("SystemRoot"), url)
|
|
return startBrowser(Command(name, args...))
|
|
}
|
|
|
|
// startBrowser starts cmd and reaps it once it ends; tests stand in for it.
|
|
var startBrowser = func(cmd *exec.Cmd) error {
|
|
if err := cmd.Start(); err != nil {
|
|
return err
|
|
}
|
|
go cmd.Wait() //nolint:errcheck
|
|
return nil
|
|
}
|
|
|
|
// browserCommand is the program and arguments that open url on goos. On
|
|
// Windows rundll32 is named by its path in the system folder: by its bare
|
|
// name Go looks it up with PATHEXT's extensions, and a PATHEXT without
|
|
// .EXE (one WSL passed on as ".CPL", #2043) finds none, though it is there.
|
|
func browserCommand(goos, systemRoot, url string) (string, []string) {
|
|
switch goos {
|
|
case "darwin":
|
|
return "open", []string{url}
|
|
case "windows":
|
|
exe := "rundll32"
|
|
if systemRoot != "" {
|
|
exe = filepath.Join(systemRoot, "System32", "rundll32.exe")
|
|
}
|
|
return exe, []string{"url.dll,FileProtocolHandler", url}
|
|
case "android":
|
|
return "termux-open-url", []string{url}
|
|
default:
|
|
return "xdg-open", []string{url}
|
|
}
|
|
}
|