Help us shape the future of Go! Take the 2026 Go Developer Survey

cdp

package
v0.65.0 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package cdp is the default browser driver: Chrome or Chromium, driven over the Chrome DevTools Protocol through the debugging pipe the browser opens on its file descriptors 3 and 4 (--remote-debugging-pipe).

It is the standard library and nothing else. There is no port to allocate or leak, no WebSocket to frame, and nothing for another process on the machine to connect to: the pipe belongs to the browser this driver started, and closes with it. Each Launch starts its own browser with its own profile directory, so two drivers share no cookie, storage or cache.

Register it in the application's test case:

var Drivers = browser.Registry{"cdp": cdp.Launch}

The browser is CHROME_PATH when it is set, and otherwise the first Chrome or Chromium found in the standard locations; with none, Launch returns an error wrapping browser.ErrNoBrowser, which skips the test on a developer's machine and fails it in CI. Headed runs and slow motion come from browser.Options.

The pipe is a pair of inherited descriptors, which Windows does not offer to a child process the same way; there Launch returns an error.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Find

func Find() (string, error)

Find returns the browser Launch would start: CHROME_PATH, or the first of the standard locations that exists. With none it returns an error wrapping browser.ErrNoBrowser that names every place it looked.

func Launch

func Launch(ctx context.Context, opts browser.Options) (browser.Driver, error)

Launch starts a browser and attaches to its page. ctx bounds the start only; the browser runs until Close. It matches browser.Factory.

Types

type Driver

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

Driver is one Chrome process with one page, driven over its pipe.

func (*Driver) AddInitScript

func (d *Driver) AddInitScript(ctx context.Context, source string) error

AddInitScript runs source in every document from now on.

func (*Driver) Click

func (d *Driver) Click(ctx context.Context, x, y float64) error

Click moves the mouse to x, y, presses the left button and releases it.

func (*Driver) Close

func (d *Driver) Close() error

Close asks the browser to quit, kills it if it does not, and removes its profile directory.

func (*Driver) Cookies

func (d *Driver) Cookies(ctx context.Context, url string) ([]*http.Cookie, error)

Cookies returns the cookies the page would send to url.

func (*Driver) EmulateMedia

func (d *Driver) EmulateMedia(ctx context.Context, m browser.Media) error

EmulateMedia sets the media type and the preferences media queries read.

func (*Driver) Evaluate

func (d *Driver) Evaluate(ctx context.Context, expression string, result any) error

Evaluate runs expression in the page and decodes its value into result.

func (*Driver) Info

func (d *Driver) Info() browser.Info

Info names the driver and the browser's version.

func (*Driver) InsertText

func (d *Driver) InsertText(ctx context.Context, text string) error

InsertText types text into the focused element.

func (*Driver) Listen

func (d *Driver) Listen(fn func(browser.Event))

Listen hands every event from now on to fn.

func (*Driver) Navigate

func (d *Driver) Navigate(ctx context.Context, url string) error

Navigate loads url and waits for the main frame's load event of that navigation.

func (*Driver) Press

func (d *Driver) Press(ctx context.Context, name string) error

Press presses and releases a key, with any modifiers named before it.

func (*Driver) Screenshot

func (d *Driver) Screenshot(ctx context.Context) ([]byte, error)

Screenshot captures the viewport as PNG.

func (*Driver) SetCookies

func (d *Driver) SetCookies(ctx context.Context, url string, cookies []*http.Cookie) error

SetCookies stores cookies as if url had set them.

func (*Driver) SetViewport

func (d *Driver) SetViewport(ctx context.Context, v browser.Viewport) error

SetViewport resizes the page.

Jump to

Keyboard shortcuts

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