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 ¶
- func Find() (string, error)
- func Launch(ctx context.Context, opts browser.Options) (browser.Driver, error)
- type Driver
- func (d *Driver) AddInitScript(ctx context.Context, source string) error
- func (d *Driver) Click(ctx context.Context, x, y float64) error
- func (d *Driver) Close() error
- func (d *Driver) Cookies(ctx context.Context, url string) ([]*http.Cookie, error)
- func (d *Driver) EmulateMedia(ctx context.Context, m browser.Media) error
- func (d *Driver) Evaluate(ctx context.Context, expression string, result any) error
- func (d *Driver) Info() browser.Info
- func (d *Driver) InsertText(ctx context.Context, text string) error
- func (d *Driver) Listen(fn func(browser.Event))
- func (d *Driver) Navigate(ctx context.Context, url string) error
- func (d *Driver) Press(ctx context.Context, name string) error
- func (d *Driver) Screenshot(ctx context.Context) ([]byte, error)
- func (d *Driver) SetCookies(ctx context.Context, url string, cookies []*http.Cookie) error
- func (d *Driver) SetViewport(ctx context.Context, v browser.Viewport) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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 ¶
AddInitScript runs source in every document from now on.
func (*Driver) Close ¶
Close asks the browser to quit, kills it if it does not, and removes its profile directory.
func (*Driver) EmulateMedia ¶
EmulateMedia sets the media type and the preferences media queries read.
func (*Driver) InsertText ¶
InsertText types text into the focused element.
func (*Driver) Navigate ¶
Navigate loads url and waits for the main frame's load event of that navigation.
func (*Driver) Screenshot ¶
Screenshot captures the viewport as PNG.
func (*Driver) SetCookies ¶
SetCookies stores cookies as if url had set them.