browser

package
v0.11.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 25, 2026 License: MIT Imports: 9 Imported by: 1 module, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
var ErrInvalidURL = errors.New("browser: invalid URL")

ErrInvalidURL reports a URL that Open refuses to hand to a launcher.

Functions

func Open

func Open(ctx context.Context, rawURL string) error

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL