Documentation
¶
Overview ¶
Package browser opens a URL in the person's default browser with the platform's own opener: xdg-open on Linux and the BSDs, open on macOS, and url.dll's FileProtocolHandler through rundll32 on Windows (which, unlike `cmd /c start`, needs no quoting of & in a URL).
It reports ErrUnavailable instead of trying when there is clearly no way to show a browser — no opener on PATH, or a Linux session with no display (SSH, containers, CI) — so callers fall back to printing the link (spec/features/local-server-and-web-console#REQ:login-links).
Index ¶
Constants ¶
This section is empty.
Variables ¶
ErrUnavailable means no browser can be launched from this process.
Functions ¶
func RefuseInTest ¶ added in v0.23.0
func RefuseInTest(url string)
RefuseInTest panics when called from a test binary, and does nothing in any other binary. Every path that can start the real opener calls it first: Opener.Open without a fake Start, and the opener `ovdb cloud login` hands to the device-login flow (its own, in another package, so it cannot go through Opener).
Types ¶
type Opener ¶
type Opener struct {
GOOS string // runtime.GOOS when empty
Getenv func(string) string // os.Getenv when nil
LookPath func(string) (string, error) // exec.LookPath when nil
Start func(name string, args ...string) error // starts without waiting when nil
}
Opener launches browsers. The zero value uses the real environment.
func (Opener) Open ¶
Open launches the default browser at url and returns without waiting for it.
A test binary must never get here with the real Start: on a desktop that opens the person's browser at a test server (it did, on macOS, at an ephemeral port), and on CI, where there is no display, nobody would notice. Open panics there, on every operating system, so the test that built its model or App without an opener fails where it is written; a test injects a fake (cli.App.OpenBrowser, the TUI's opener, or Opener.Start). testing.Testing is false in every binary a person runs.