chromedputil

package
v0.0.0-...-e1b65c3 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2025 License: Apache-2.0 Imports: 14 Imported by: 0

README

Package cloudeng.io/webapp/devtest/chromedputil

import cloudeng.io/webapp/devtest/chromedputil

Package chromedputil provides utility functions for working with the Chrome DevTools Protocol via github.com/chromedp.

Functions

Func ConsoleArgsAsJSON
func ConsoleArgsAsJSON(ctx context.Context, event *runtime.EventConsoleAPICalled) ([][]byte, error)

ConsoleArgsAsJSON converts the console API call arguments to a slice of marshalled JSON data, one per each argument to the original console.log call.

Func GetRemoteObjectRef
func GetRemoteObjectRef(ctx context.Context, name string) (*runtime.RemoteObject, error)

GetRemoteObjectRef retrieves a remote object's metadata, ie. type, object id etc (but not it's value).

Func GetRemoteObjectValueJSON
func GetRemoteObjectValueJSON(ctx context.Context, object *runtime.RemoteObject) (*runtime.RemoteObject, jsontext.Value, error)

GetRemoteObjectValueJSON retrieves a remote object's (using ObjectID) value using JSON serialization. The object is looked up by its ID and hence the supplied ObjectID must be a reference to the object with the ObjectID field set. Objects which already contain a JSON value will return that value immediately. NOTE that GetRemoteObjectValueJSON will return an empty or incomplete serialization for platform objects, the ClassName will generally be indicative of whether the object is a platform object, e.g Response or Promise.

Func IsPlatformObject
func IsPlatformObject(obj *runtime.RemoteObject) bool

IsPlatformObject returns true if the given remote object is a platform object. The obj argument must have been obtained via a call to GetRemoteObjectValueJSON.

Func IsPlatformObjectError
func IsPlatformObjectError(err error) bool

IsPlatformObjectError checks if the error is due to a platform object serialization error. The only reliable way to determine if an object is a platform object in chrome is to attempt a deep serialization and check for this error.

Func ListGlobalFunctions
func ListGlobalFunctions(ctx context.Context) ([]string, error)

ListGlobalFunctions returns a list of all global function names defined in the current context.

Func Listen
func Listen(ctx context.Context, handlers ...func(ctx context.Context, ev any) bool)

Listen sets up a listener for Chrome DevTools Protocol events and calls each of the supplied handlers in turn when an event is received. The first handler to return true stops the event propagation.

Func NewListenHandler
func NewListenHandler[T any](ch chan<- T) func(ctx context.Context, ev any) bool

NewListenHandler returns a handler for a specific event type that forwards the event to the provided channel.

Func RunLoggingListener
func RunLoggingListener(ctx context.Context, logger *slog.Logger, opts ...LoggingOption) chan struct{}

RunLoggingListener starts the logging listener for Chrome DevTools Protocol events. It returns a channel that is closed when the goroutine that listens on events terminates.

Func SourceScript
func SourceScript(ctx context.Context, script string) error

SourceScript loads a JavaScript script into the current page.

Func WaitForPromise
func WaitForPromise(p *runtime.EvaluateParams) *runtime.EvaluateParams

WaitForPromise waits for a promise to resolve in the given evaluate parameters.

Func WithContextForCI
func WithContextForCI(ctx context.Context, execAllocOpts []chromedp.ExecAllocatorOption, opts ...chromedp.ContextOption) (context.Context, func())

WithContextForCI returns a chromedp context that may be different on a CI system than when running locally. The CI configuration may disable sandboxing etc. The ExecAllocator used is created with default options (eg. headless) if execAllocOpts is nil or empty via a call WithExecAllocatorForCI,

Func WithExecAllocatorForCI
func WithExecAllocatorForCI(ctx context.Context, opts ...chromedp.ExecAllocatorOption) (context.Context, func())

WithExecAllocatorForCI returns a chromedp context with an ExecAllocator that may be configured differently on a CI system than when running locally. The CI configuration may disable sandboxing for example.

Types

Type LoggingOption
type LoggingOption func(*loggingOptions)

LoggingOption represents options to RunLoggingListener.

Functions
func WithAnyEventLogging() LoggingOption

WithAnyEventLogging enables logging for events of type 'any'. This is a catch all and should generally be the last handler in the list.

func WithConsoleLogging() LoggingOption

WithConsoleLogging enables logging of events of type 'runtime.EventConsoleAPICalled'.

func WithEventEntryLogging() LoggingOption

WithEventEntryLogging enables logging of events of type 'log.EventEntryAdded'.

func WithExceptionLogging() LoggingOption

WithExceptionLogging enables logging of events of type 'runtime.EventExceptionThrown'.

func WithNetworkLogging() LoggingOption

WithNetworkLogging enables logging of events of type 'network.EventResponseReceived'.

Documentation

Overview

Package chromedputil provides utility functions for working with the Chrome DevTools Protocol via github.com/chromedp.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConsoleArgsAsJSON

func ConsoleArgsAsJSON(ctx context.Context, event *runtime.EventConsoleAPICalled) ([][]byte, error)

ConsoleArgsAsJSON converts the console API call arguments to a slice of marshalled JSON data, one per each argument to the original console.log call.

func GetRemoteObjectRef

func GetRemoteObjectRef(ctx context.Context, name string) (*runtime.RemoteObject, error)

GetRemoteObjectRef retrieves a remote object's metadata, ie. type, object id etc (but not it's value).

func GetRemoteObjectValueJSON

func GetRemoteObjectValueJSON(ctx context.Context, object *runtime.RemoteObject) (*runtime.RemoteObject, jsontext.Value, error)

GetRemoteObjectValueJSON retrieves a remote object's (using ObjectID) value using JSON serialization. The object is looked up by its ID and hence the supplied ObjectID must be a reference to the object with the ObjectID field set. Objects which already contain a JSON value will return that value immediately. NOTE that GetRemoteObjectValueJSON will return an empty or incomplete serialization for platform objects, the ClassName will generally be indicative of whether the object is a platform object, e.g Response or Promise.

func IsPlatformObject

func IsPlatformObject(obj *runtime.RemoteObject) bool

IsPlatformObject returns true if the given remote object is a platform object. The obj argument must have been obtained via a call to GetRemoteObjectValueJSON.

func IsPlatformObjectError

func IsPlatformObjectError(err error) bool

IsPlatformObjectError checks if the error is due to a platform object serialization error. The only reliable way to determine if an object is a platform object in chrome is to attempt a deep serialization and check for this error.

func ListGlobalFunctions

func ListGlobalFunctions(ctx context.Context) ([]string, error)

ListGlobalFunctions returns a list of all global function names defined in the current context.

func Listen

func Listen(ctx context.Context, handlers ...func(ctx context.Context, ev any) bool)

Listen sets up a listener for Chrome DevTools Protocol events and calls each of the supplied handlers in turn when an event is received. The first handler to return true stops the event propagation.

func NewListenHandler

func NewListenHandler[T any](ch chan<- T) func(ctx context.Context, ev any) bool

NewListenHandler returns a handler for a specific event type that forwards the event to the provided channel.

func RunLoggingListener

func RunLoggingListener(ctx context.Context, logger *slog.Logger, opts ...LoggingOption) chan struct{}

RunLoggingListener starts the logging listener for Chrome DevTools Protocol events. It returns a channel that is closed when the goroutine that listens on events terminates.

func SourceScript

func SourceScript(ctx context.Context, script string) error

SourceScript loads a JavaScript script into the current page.

func WaitForPromise

func WaitForPromise(p *runtime.EvaluateParams) *runtime.EvaluateParams

WaitForPromise waits for a promise to resolve in the given evaluate parameters.

func WithContextForCI

func WithContextForCI(ctx context.Context, execAllocOpts []chromedp.ExecAllocatorOption, opts ...chromedp.ContextOption) (context.Context, func())

WithContextForCI returns a chromedp context that may be different on a CI system than when running locally. The CI configuration may disable sandboxing etc. The ExecAllocator used is created with default options (eg. headless) if execAllocOpts is nil or empty via a call WithExecAllocatorForCI,

func WithExecAllocatorForCI

func WithExecAllocatorForCI(ctx context.Context, opts ...chromedp.ExecAllocatorOption) (context.Context, func())

WithExecAllocatorForCI returns a chromedp context with an ExecAllocator that may be configured differently on a CI system than when running locally. The CI configuration may disable sandboxing for example.

Types

type LoggingOption

type LoggingOption func(*loggingOptions)

LoggingOption represents options to RunLoggingListener.

func WithAnyEventLogging

func WithAnyEventLogging() LoggingOption

WithAnyEventLogging enables logging for events of type 'any'. This is a catch all and should generally be the last handler in the list.

func WithConsoleLogging

func WithConsoleLogging() LoggingOption

WithConsoleLogging enables logging of events of type 'runtime.EventConsoleAPICalled'.

func WithEventEntryLogging

func WithEventEntryLogging() LoggingOption

WithEventEntryLogging enables logging of events of type 'log.EventEntryAdded'.

func WithExceptionLogging

func WithExceptionLogging() LoggingOption

WithExceptionLogging enables logging of events of type 'runtime.EventExceptionThrown'.

func WithNetworkLogging

func WithNetworkLogging() LoggingOption

WithNetworkLogging enables logging of events of type 'network.EventResponseReceived'.

Jump to

Keyboard shortcuts

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