Documentation
¶
Overview ¶
Package browser opens a web page in the user's browser, such as the sign-in page of an OAuth flow.
Open runs the platform's launcher, without cgo and without a shell: open on macOS, rundll32 url.dll,FileProtocolHandler on Windows, and xdg-open everywhere else. It takes http and https URLs only, so a URL from elsewhere cannot make the launcher open a local file or start another program through a scheme of its own.
Opening a page can fail without anyone noticing: there may be no desktop, no browser, or a browser that shows the page on another screen. Print the URL as well, so the user can open it by hand.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidURL = errors.New("browser: invalid URL")
ErrInvalidURL reports a URL that Open refuses to hand to a launcher.
Functions ¶
func Open ¶
Open opens rawURL in the user's browser and returns once the launcher has started; it does not wait for the page to open, and a launcher that fails later goes unnoticed. ctx bounds the launcher: when ctx ends while it still runs, it is killed.
Only an absolute http or https URL with a host is opened. A URL that is not valid UTF-8 or holds white space or a control character (C0, DEL or C1) is refused as well, since it is handed to a program that may read it further: escape such characters as %XX. A refused URL is reported with an error wrapping ErrInvalidURL that does not repeat the URL, which may carry a credential.
The launcher is open on macOS, rundll32 url.dll,FileProtocolHandler on Windows, and xdg-open on every other platform. It is found through PATH and gets the URL as one argument, never through a shell. Its output is discarded.
Types ¶
This section is empty.