Documentation ¶
Overview ¶
Package cdputil provides utilities to communicate with Chrome via Chrome DevTools Protocol.
Index ¶
- Constants
- type Conn
- func (c *Conn) CallOn(ctx context.Context, objectID runtime.RemoteObjectID, out interface{}, ...) (*runtime.ExceptionDetails, error)
- func (c *Conn) Close() error
- func (c *Conn) CloseTarget(ctx context.Context) error
- func (c *Conn) ConsoleAPICalled(ctx context.Context) (runtime.ConsoleAPICalledClient, error)
- func (c *Conn) DispatchKeyEvent(ctx context.Context, args *input.DispatchKeyEventArgs) error
- func (c *Conn) DispatchMouseEvent(ctx context.Context, args *input.DispatchMouseEventArgs) error
- func (c *Conn) Eval(ctx context.Context, expr string, awaitPromise bool, out interface{}) (*runtime.ExceptionDetails, error)
- func (c *Conn) GetMediaPropertiesChangedObserver(ctx context.Context) (observer media.PlayerPropertiesChangedClient, err error)
- func (c *Conn) Navigate(ctx context.Context, url string) error
- func (c *Conn) PageContent(ctx context.Context) (string, error)
- func (c *Conn) ReleaseAllObjects(ctx context.Context) error
- func (c *Conn) ReleaseObject(ctx context.Context, object runtime.RemoteObject) error
- func (c *Conn) ReleaseObjectGroup(ctx context.Context, objectGroup string) error
- func (c *Conn) StartProfiling(ctx context.Context) error
- func (c *Conn) StopProfiling(ctx context.Context) (*profiler.TakePreciseCoverageReply, error)
- func (c *Conn) WaitForExpr(ctx context.Context, expr string, ea ErrorAction, timeout time.Duration) error
- type CreateTargetOption
- type ErrorAction
- type PortWaitOption
- type Session
- func (s *Session) Close(ctx context.Context) error
- func (s *Session) CloseTarget(ctx context.Context, id target.ID) error
- func (s *Session) CreateTarget(ctx context.Context, url string, opts ...CreateTargetOption) (target.ID, error)
- func (s *Session) DebugAddrPort() string
- func (s *Session) FindTargets(ctx context.Context, tm TargetMatcher) ([]*target.Info, error)
- func (s *Session) NewConn(ctx context.Context, id target.ID) (conn *Conn, retErr error)
- func (s *Session) StartSystemTracing(ctx context.Context, perfettoConfig []byte) error
- func (s *Session) StartTracing(ctx context.Context, categories []string, opts ...TraceOption) error
- func (s *Session) StopTracing(ctx context.Context) (*perfetto_proto.Trace, error)
- func (s *Session) WaitForTarget(ctx context.Context, tm TargetMatcher) (*target.Info, error)
- type TargetMatcher
- type TraceOption
Constants ¶
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) CloseTarget ¶
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 ¶
ConsoleAPICalled creates a client for ConsoleAPICalled events.
func (*Conn) DispatchKeyEvent ¶
DispatchKeyEvent dispatches a key event to the page.
func (*Conn) DispatchMouseEvent ¶
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) PageContent ¶
PageContent returns the current top-level page content.
func (*Conn) ReleaseAllObjects ¶
ReleaseAllObjects releases all remote JavaScript objects not released yet.
func (*Conn) ReleaseObject ¶
ReleaseObject releases the specified object.
func (*Conn) ReleaseObjectGroup ¶
ReleaseObjectGroup releases the specified object group.
func (*Conn) StartProfiling ¶
StartProfiling starts the profiling for current connection.
func (*Conn) StopProfiling ¶
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) CloseTarget ¶
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 ¶
DebugAddrPort returns the addr:port at which Chrome is listening for DevTools connections, e.g. "127.0.0.1:38725".
func (*Session) FindTargets ¶
FindTargets returns the info about Targets, which satisfies the given cond condition.
func (*Session) StartSystemTracing ¶
StartSystemTracing starts trace events collection from the system tracing service using the marshaled binary protobuf trace config.
func (*Session) StartTracing ¶
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 ¶
StopTracing stops trace collection and returns the collected trace events.
func (*Session) WaitForTarget ¶
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 ¶
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.