Documentation
¶
Overview ¶
Package chromedputil provides utility functions for working with the Chrome DevTools Protocol via github.com/chromedp.
Index ¶
- func ConsoleArgsAsJSON(ctx context.Context, event *runtime.EventConsoleAPICalled) ([][]byte, error)
- func GetRemoteObjectRef(ctx context.Context, name string) (*runtime.RemoteObject, error)
- func GetRemoteObjectValueJSON(ctx context.Context, object *runtime.RemoteObject) (*runtime.RemoteObject, jsontext.Value, error)
- func IsPlatformObject(obj *runtime.RemoteObject) bool
- func IsPlatformObjectError(err error) bool
- func ListGlobalFunctions(ctx context.Context) ([]string, error)
- func Listen(ctx context.Context, handlers ...func(ctx context.Context, ev any) bool)
- func NewListenHandler[T any](ch chan<- T) func(ctx context.Context, ev any) bool
- func RunLoggingListener(ctx context.Context, logger *slog.Logger, opts ...LoggingOption) chan struct{}
- func SourceScript(ctx context.Context, script string) error
- func WaitForPromise(p *runtime.EvaluateParams) *runtime.EvaluateParams
- func WithContextForCI(ctx context.Context, execAllocOpts []chromedp.ExecAllocatorOption, ...) (context.Context, func())
- func WithExecAllocatorForCI(ctx context.Context, opts ...chromedp.ExecAllocatorOption) (context.Context, func())
- type LoggingOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConsoleArgsAsJSON ¶
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 ¶
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 ¶
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 ¶
ListGlobalFunctions returns a list of all global function names defined in the current context.
func Listen ¶
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 ¶
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 ¶
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'.