cdputil

package
v0.0.0-...-683b059 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2022 License: BSD-3-Clause Imports: 24 Imported by: 0

Documentation

Overview

Package cdputil provides utilities to communicate with Chrome via Chrome DevTools Protocol.

Index

Constants

View Source
const (
	// DebuggingPortPath is a file where Chrome writes debugging port.
	DebuggingPortPath = "/home/chronos/DevToolsActivePort"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Conn

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

Conn is the connection to a web content view, e.g. a tab.

func (*Conn) CallOn

func (c *Conn) CallOn(ctx context.Context, objectID runtime.RemoteObjectID, out interface{}, fn string, args ...interface{}) (*runtime.ExceptionDetails, error)

CallOn calls the given JavaScript function on the given Object. The passed arguments must be of type *runtime.RemoteObject or be able to marshal to JSON. If fn is an arrow function, the "this" in the function body will be the window object instead of the object referred to by runtime.RemoteObjectID objectID, and that will probably lead to unintended behavior. If out is given, the returned value is set. If out is a *runtime.RemoteObject, a reference to the result is returned. The *runtime.RemoteObject should get released or the memory it references will not be freed. In case of JavaScript exceptions, an error is return.

func (*Conn) Close

func (c *Conn) Close() error

Close releases the resources associated with the connection.

func (*Conn) CloseTarget

func (c *Conn) CloseTarget(ctx context.Context) error

CloseTarget closes the web content (e.g. tab) associated with c. Close must still be called to free associated resources. Tests should not feel obligated to call this to clean up.

func (*Conn) ConsoleAPICalled

func (c *Conn) ConsoleAPICalled(ctx context.Context) (runtime.ConsoleAPICalledClient, error)

ConsoleAPICalled creates a client for ConsoleAPICalled events.

func (*Conn) DispatchKeyEvent

func (c *Conn) DispatchKeyEvent(ctx context.Context, args *input.DispatchKeyEventArgs) error

DispatchKeyEvent dispatches a key event to the page.

func (*Conn) DispatchMouseEvent

func (c *Conn) DispatchMouseEvent(ctx context.Context, args *input.DispatchMouseEventArgs) error

DispatchMouseEvent dispatches a mouse event to the page.

func (*Conn) Eval

func (c *Conn) Eval(ctx context.Context, expr string, awaitPromise bool, out interface{}) (*runtime.ExceptionDetails, error)

Eval evaluates the given JavaScript expression. If awaitPromise is set to true, this method waits until it is fulfilled. If out is given, the returned value is set. If out is a *runtime.RemoteObject, a reference to the result is returned. The *runtime.RemoteObject should get released or the memory it references will not be freed. In case of JavaScript exceptions, errorText and exc are returned.

func (*Conn) GetMediaPropertiesChangedObserver

func (c *Conn) GetMediaPropertiesChangedObserver(ctx context.Context) (observer media.PlayerPropertiesChangedClient, err error)

GetMediaPropertiesChangedObserver enables media logging for the current connection and retrieves a properties change observer.

func (*Conn) Navigate

func (c *Conn) Navigate(ctx context.Context, url string) error

Navigate navigates to url.

func (*Conn) PageContent

func (c *Conn) PageContent(ctx context.Context) (string, error)

PageContent returns the current top-level page content.

func (*Conn) ReleaseAllObjects

func (c *Conn) ReleaseAllObjects(ctx context.Context) error

ReleaseAllObjects releases all remote JavaScript objects not released yet.

func (*Conn) ReleaseObject

func (c *Conn) ReleaseObject(ctx context.Context, object runtime.RemoteObject) error

ReleaseObject releases the specified object.

func (*Conn) ReleaseObjectGroup

func (c *Conn) ReleaseObjectGroup(ctx context.Context, objectGroup string) error

ReleaseObjectGroup releases the specified object group.

func (*Conn) StartProfiling

func (c *Conn) StartProfiling(ctx context.Context) error

StartProfiling starts the profiling for current connection.

func (*Conn) StopProfiling

func (c *Conn) StopProfiling(ctx context.Context) (*profiler.TakePreciseCoverageReply, error)

StopProfiling stops the profiling for current connection.

func (*Conn) WaitForExpr

func (c *Conn) WaitForExpr(ctx context.Context, expr string, ea ErrorAction, timeout time.Duration) error

WaitForExpr repeatedly evaluates the JavaScript expression expr until it evaluates to true. The behavior on evaluation errors depends on the value of ea.

type CreateTargetOption

type CreateTargetOption func(args *target.CreateTargetArgs)

CreateTargetOption specifies opptional parameter.

func WithBackground

func WithBackground() CreateTargetOption

WithBackground returns an option to create the target in background.

func WithNewWindow

func WithNewWindow() CreateTargetOption

WithNewWindow returns an option to create the target in a new window.

type ErrorAction

type ErrorAction int

ErrorAction defines the behavior of WaitForExpr if the given expression reports an exception.

const (
	// ContinueOnError means to continue to poll the expression until satisfied (or timed out).
	ContinueOnError ErrorAction = iota

	// ExitOnError means to immediately return from the polling if an error is found.
	ExitOnError
)

type PortWaitOption

type PortWaitOption bool

PortWaitOption controls whether the NewSession should wait for the port file to be created.

const (
	// NoWaitPort does not wait for the port file, so if missing it will
	// fail immediately.
	NoWaitPort PortWaitOption = false

	// WaitPort waits for the port file to be created.
	WaitPort PortWaitOption = true
)

type Session

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

Session maintains the connection to talk to the browser in Chrome DevTools Protocol over WebSocket.

func NewSession

func NewSession(ctx context.Context, debuggingPortPath string, portWait PortWaitOption) (sess *Session, retErr error)

NewSession establishes a Chrome DevTools Protocol WebSocket connection to the browser. This assumes that Chrome listens the debugging port, which means Chrome needs to be restarted with a --remote-debugging-port flag.

func (*Session) Close

func (s *Session) Close(ctx context.Context) error

Close shuts down the connection to the browser.

func (*Session) CloseTarget

func (s *Session) CloseTarget(ctx context.Context, id target.ID) error

CloseTarget closes the target identified by the given id.

func (*Session) CreateTarget

func (s *Session) CreateTarget(ctx context.Context, url string, opts ...CreateTargetOption) (target.ID, error)

CreateTarget opens a new tab displaying the given url. Additional options customizes the target.

func (*Session) DebugAddrPort

func (s *Session) DebugAddrPort() string

DebugAddrPort returns the addr:port at which Chrome is listening for DevTools connections, e.g. "127.0.0.1:38725".

func (*Session) FindTargets

func (s *Session) FindTargets(ctx context.Context, tm TargetMatcher) ([]*target.Info, error)

FindTargets returns the info about Targets, which satisfies the given cond condition.

func (*Session) NewConn

func (s *Session) NewConn(ctx context.Context, id target.ID) (conn *Conn, retErr error)

NewConn creates a new connection to the given id.

func (*Session) StartSystemTracing

func (s *Session) StartSystemTracing(ctx context.Context, perfettoConfig []byte) error

StartSystemTracing starts trace events collection from the system tracing service using the marshaled binary protobuf trace config.

func (*Session) StartTracing

func (s *Session) StartTracing(ctx context.Context, categories []string, opts ...TraceOption) error

StartTracing starts trace events collection for the selected categories. Android categories must be prefixed with "disabled-by-default-android ", e.g. for the gfx category, use "disabled-by-default-android gfx", including the space.

func (*Session) StopTracing

func (s *Session) StopTracing(ctx context.Context) (*perfetto_proto.Trace, error)

StopTracing stops trace collection and returns the collected trace events.

func (*Session) WaitForTarget

func (s *Session) WaitForTarget(ctx context.Context, tm TargetMatcher) (*target.Info, error)

WaitForTarget iterates through all available targets and returns a connection to the first one that is matched by tm. It polls until the target is found or ctx's deadline expires. An error is returned if no target is found or tm matches multiple targets.

type TargetMatcher

type TargetMatcher func(t *target.Info) bool

TargetMatcher is a caller-provided function that matches targets with specific characteristics.

type TraceOption

type TraceOption func(*tracing.TraceConfig)

TraceOption is the option to cusotmize the tracing behaviors.

func DisableSystrace

func DisableSystrace() TraceOption

DisableSystrace is a TraceOption. When specified, it disables the systrace.

Jump to

Keyboard shortcuts

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