browser

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Request

func Request(data map[string]any, opts ...Option) (map[string]any, error)

Types

type BrowserRunner

type BrowserRunner interface {
	Run(ctx context.Context, actions ...chromedp.Action) error
}

BrowserRunner defines the interface for running browser actions

type Callback

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

type ChromeDPAction

type ChromeDPAction struct {
	ID        string   `map:"id"`
	Name      string   `map:"name"`
	URL       string   `map:"url"`
	Selector  string   `map:"selector"`
	Attribute []string `map:"attribute"`
	Value     string   `map:"value"`
	Path      string   `map:"path"` // Deprecated: use FilePath from results
	Quality   int      `map:"quality"`
	// contains filtered or unexported fields
}

func NewChromeDPAction

func NewChromeDPAction() *ChromeDPAction

type ChromeDPRunner

type ChromeDPRunner struct{}

ChromeDPRunner implements BrowserRunner using the actual ChromeDP

func (*ChromeDPRunner) Run

func (r *ChromeDPRunner) Run(ctx context.Context, actions ...chromedp.Action) error

Run executes actions using ChromeDP

type MockRunner

type MockRunner struct {
	RunFunc     func(ctx context.Context, actions ...chromedp.Action) error
	CallHistory [][]chromedp.Action
	// contains filtered or unexported fields
}

MockRunner implements BrowserRunner for testing

func NewMockRunner

func NewMockRunner() *MockRunner

NewMockRunner creates a new mock browser runner

func (*MockRunner) GetAllCalls

func (m *MockRunner) GetAllCalls() [][]chromedp.Action

GetAllCalls returns all recorded Run calls

func (*MockRunner) GetCallCount

func (m *MockRunner) GetCallCount() int

GetCallCount returns the number of Run calls made

func (*MockRunner) GetLastCall

func (m *MockRunner) GetLastCall() []chromedp.Action

GetLastCall returns the actions from the most recent Run call

func (*MockRunner) Run

func (m *MockRunner) Run(ctx context.Context, actions ...chromedp.Action) error

Run records the call and optionally executes a custom function

func (*MockRunner) SetRunFunc

func (m *MockRunner) SetRunFunc(fn func(ctx context.Context, actions ...chromedp.Action) error)

SetRunFunc sets a custom function to execute when Run is called

type Option

type Option func(*Callback)

func WithAfter

func WithAfter(f func(res *Res)) Option

func WithBefore

func WithBefore(f func(req *Req)) Option

func WithInBrowser

func WithInBrowser(f func(s string, i ...interface{})) Option

type Req

type Req struct {
	Actions  []*ChromeDPAction `map:"actions"`
	Headless bool              `map:"headless"`
	WindowW  int               `map:"window_w"`
	WindowH  int               `map:"window_h"`
	Timeout  time.Duration
	// contains filtered or unexported fields
}

func NewReq

func NewReq() *Req

type Res

type Res struct {
	Code      int               `map:"code"`
	Results   map[string]string `map:"results"`
	FilePaths map[string]string `map:"filepaths"` // New: for binary file paths (action_id -> filepath)
}

type Result

type Result struct {
	Req    Req           `map:"req"`
	Res    Res           `map:"res"`
	RT     time.Duration `map:"rt"`
	Status int           `map:"status"`
}

Jump to

Keyboard shortcuts

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