chrome

package
v0.0.0-...-bb8c128 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2024 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

package chrome provides helper functions to execute JS in a Chrome browser

This would ordinarily be done via a Chrome struct but Go does not allow generic methods, only generic static functions, producing "method must have no type parameters".

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MustRunAsyncFn

func MustRunAsyncFn[T any](t ct.TestLike, ctx context.Context, js string) *T

MustRunAsyncFn is RunAsyncFn but fails the test if an error is returned when executing.

Run an anonymous async iffe in the browser. Set the type parameter to a basic data type which can be returned as JSON e.g string, map[string]any, []string. If you do not want to return anything, use chrome.Void

func RunAsyncFn

func RunAsyncFn[T any](t ct.TestLike, ctx context.Context, js string) (*T, error)

Run an anonymous async iffe in the browser. Set the type parameter to a basic data type which can be returned as JSON e.g string, map[string]any, []string. If you do not want to return anything, use chrome.Void. For example:

result, err := RunAsyncFn[string](t, ctx, "return await getSomeString()")
void, err := RunAsyncFn[chrome.Void](t, ctx, "doSomething(); await doSomethingElse();")

Types

type Browser

type Browser struct {
	BaseURL string
	Ctx     context.Context
	Cancel  func()
}

func RunHeadless

func RunHeadless(onConsoleLog func(s string), requiresPersistance bool, listenPort int) (*Browser, error)

type Void

type Void *runtime.RemoteObject

Void is a type which can be used when you want to run an async function without returning anything. It can stop large responses causing errors "Object reference chain is too long (-32000)" when we don't care about the response.

Jump to

Keyboard shortcuts

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