chrome

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package chrome drives a headless Chrome over the DevTools protocol, for the tests of live pages: open pages, click, type, press keys and evaluate JavaScript. It is a small hand-written client over the WebSocket library the framework already uses.

Index

Constants

This section is empty.

Variables

View Source
var Timeout = 10 * time.Second

Timeout bounds every call and wait.

Functions

func Find

func Find() string

Find returns a Chrome or Chromium binary: $VUKA_CHROME, then the usual install locations and PATH names; "" when there is none.

Types

type Browser

type Browser struct {
	// contains filtered or unexported fields
}

Browser is a running headless Chrome.

func Launch

func Launch(t testing.TB) *Browser

Launch starts Chrome for the test, closed when it ends; it skips the test when there is no Chrome (fails it under CI).

func (*Browser) Load added in v0.11.0

func (b *Browser) Load(url string) *Page

Load opens url in a new tab and waits for it to load: a page without Vuka's runtime (a login form, a single-page app).

func (*Browser) Open

func (b *Browser) Open(url string) *Page

Open opens url in a new tab and waits for the page to be live.

func (*Browser) Visit added in v0.5.0

func (b *Browser) Visit(url string) *Page

Visit opens url in a new tab and waits for it to load and its runtime to run: a page that never connects (one with only JS commands).

type Page

type Page struct {
	// contains filtered or unexported fields
}

Page is a tab.

func (*Page) Click

func (p *Page) Click(sel string)

Click clicks the middle of the element matching sel with the mouse.

func (*Page) ClickElement added in v0.9.0

func (p *Page) ClickElement(expr string)

ClickElement clicks the middle of the element a JavaScript expression finds (waiting for it) with the mouse: one in a shadow root, say.

func (*Page) Drop added in v0.3.0

func (p *Page) Drop()

Drop closes the page's WebSockets from the page's side, as a lost connection does.

func (*Page) Eval

func (p *Page) Eval(js string, out any) error

Eval evaluates a JavaScript expression (awaiting a promise) and decodes its value into out, when not nil.

func (*Page) Press

func (p *Page) Press(key string)

Press presses a key: "Enter", "Escape", …

func (*Page) Screenshot added in v0.9.0

func (p *Page) Screenshot(path string)

Screenshot saves a PNG of the page's viewport at path.

func (*Page) Text

func (p *Page) Text(sel string) string

Text is the text of the first element matching a CSS selector.

func (*Page) Type

func (p *Page) Type(sel, text string)

Type focuses the element matching sel and types text into it.

func (*Page) Viewport added in v0.9.0

func (p *Page) Viewport(width, height int, dark bool)

Viewport sets the page's size in CSS pixels, and whether it prefers a dark color scheme.

func (*Page) Wait

func (p *Page) Wait(js string)

Wait waits for a JavaScript expression to be true.

func (*Page) WaitText

func (p *Page) WaitText(sel, want string)

WaitText waits for the element matching sel to have the text want.

func (*Page) Wire added in v0.3.0

func (p *Page) Wire() Wire

Wire reads the page's WebSocket counters.

type Wire added in v0.3.0

type Wire struct{ In, Out, Msgs int }

Wire is what the page's WebSockets carried so far: payload bytes received and sent (before any compression), and messages received.

Jump to

Keyboard shortcuts

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