browser

package
v1.0.0-beta.4 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrChromeNotFound    = errors.New("chrome executable not found")
	ErrBrowserClosed     = errors.New("browser context is closed")
	ErrScriptExecution   = errors.New("script execution failed")
	ErrNavigationTimeout = errors.New("navigation timeout")
)

Functions

This section is empty.

Types

type ChromeController

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

ChromeController implements Controller interface using chromedp

func NewController

func NewController(opts Options) (*ChromeController, error)

NewController creates a new browser controller

func (*ChromeController) Close

func (c *ChromeController) Close() error

Close closes the browser context

func (*ChromeController) ExecuteScript

func (c *ChromeController) ExecuteScript(ctx context.Context, script string) (interface{}, error)

ExecuteScript executes JavaScript and returns the result

func (*ChromeController) Navigate

func (c *ChromeController) Navigate(ctx context.Context, url string) error

Navigate navigates to the specified URL

func (*ChromeController) ScrollPage

func (c *ChromeController) ScrollPage(ctx context.Context, offset int) error

ScrollPage scrolls the page by the specified offset

func (*ChromeController) WaitForElement

func (c *ChromeController) WaitForElement(ctx context.Context, selector string) error

WaitForElement waits for an element to be present

type Controller

type Controller interface {
	Navigate(ctx context.Context, url string) error
	ExecuteScript(ctx context.Context, script string) (interface{}, error)
	WaitForElement(ctx context.Context, selector string) error
	ScrollPage(ctx context.Context, offset int) error
	Close() error
}

Controller defines the interface for browser automation

type MockController

type MockController struct {

	// Test data
	NavigateFunc       func(ctx context.Context, url string) error
	ExecuteScriptFunc  func(ctx context.Context, script string) (interface{}, error)
	WaitForElementFunc func(ctx context.Context, selector string) error
	ScrollPageFunc     func(ctx context.Context, offset int) error
	CloseFunc          func() error

	// Call tracking
	NavigateCalls       []string
	ExecuteScriptCalls  []string
	WaitForElementCalls []string
	ScrollPageCalls     []int
	CloseCalls          int

	// State
	Closed bool
	// contains filtered or unexported fields
}

MockController implements Controller interface for testing

func NewMockController

func NewMockController() *MockController

NewMockController creates a new mock browser controller

func (*MockController) Close

func (m *MockController) Close() error

Close mocks browser closure

func (*MockController) ExecuteScript

func (m *MockController) ExecuteScript(ctx context.Context, script string) (interface{}, error)

ExecuteScript mocks JavaScript execution

func (*MockController) GetExecuteScriptCalls

func (m *MockController) GetExecuteScriptCalls() []string

GetExecuteScriptCalls returns all ExecuteScript calls

func (*MockController) GetNavigateCalls

func (m *MockController) GetNavigateCalls() []string

GetNavigateCalls returns all Navigate calls

func (*MockController) Navigate

func (m *MockController) Navigate(ctx context.Context, url string) error

Navigate mocks navigation to a URL

func (*MockController) Reset

func (m *MockController) Reset()

Reset clears all call tracking and resets state

func (*MockController) ScrollPage

func (m *MockController) ScrollPage(ctx context.Context, offset int) error

ScrollPage mocks page scrolling

func (*MockController) SetExecuteScriptError

func (m *MockController) SetExecuteScriptError(err error)

SetExecuteScriptError sets an error to be returned by ExecuteScript

func (*MockController) SetExecuteScriptResult

func (m *MockController) SetExecuteScriptResult(result interface{})

SetExecuteScriptResult sets a custom result to be returned by ExecuteScript

func (*MockController) SetNavigateError

func (m *MockController) SetNavigateError(err error)

SetNavigateError sets an error to be returned by Navigate

func (*MockController) WaitForElement

func (m *MockController) WaitForElement(ctx context.Context, selector string) error

WaitForElement mocks waiting for an element

type Options

type Options struct {
	Headless     bool
	Timeout      int // seconds
	UserAgent    string
	WindowWidth  int
	WindowHeight int
}

Options configures browser behavior

Jump to

Keyboard shortcuts

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