allwright

API ReferenceGoBrowser

Browser

Launch a Chromium or Firefox session and hold the handle every other call goes through. Every method here (and everywhere else in the Go client) takes a context.Context first, for cancellation and timeouts.

LaunchChrome / LaunchFirefox

FunctionSince v0.0.14

Launches a Chromium or Firefox session and returns a handle to it. LaunchBrowser(ctx, browserKind, options) is the shared, lower-level entry point both wrap.

func LaunchChrome(ctx context.Context, options LaunchOptions) (*Browser, error)
func LaunchFirefox(ctx context.Context, options LaunchOptions) (*Browser, error)

Example

browser, err := allwright.LaunchFirefox(ctx, allwright.LaunchOptions{})

(*Browser).Page

MethodSince v0.0.33

Returns the browser's initial page/tab. InitialTab and InitialPage are aliases for the same call.

func (b *Browser) Page() *Page

(*Browser).NewPage / NewTab

MethodSince v0.0.33

Opens an additional tab in the same browser session and returns its handle. Pages() lists every tab tracked so far.

func (b *Browser) NewPage(ctx context.Context, options ...CommandOptions) (*Page, error)

(*Browser).Close

MethodSince v0.0.14

Closes the browser session and its underlying stream.

func (b *Browser) Close(ctx context.Context) error

Example

defer browser.Close(ctx)

LaunchOptions

TypeSince v0.0.14

Passed to LaunchChrome/LaunchFirefox/LaunchBrowser: an explicit browser binary path and a launch timeout.

type LaunchOptions struct {
	BrowserBinary string
	Timeout       time.Duration
}