browser

package
v0.107.6-beta.22 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: Apache-2.0 Imports: 34 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DriverRod      = "rod"
	DriverChromedp = "chromedp"
)

Variables

View Source
var AllowPrivateURLs = false
View Source
var Driver = func() string {
	if d := os.Getenv("K_BRAIN_BROWSER_DRIVER"); d != "" {
		return d
	}
	return "rod"
}()
View Source
var ErrNoLiveBrowser = errors.New("no live browser with remote debugging found")
View Source
var ErrPermissionBlocked = errors.New("chrome permission-blocked")

Functions

func CheckPrivateURL

func CheckPrivateURL(ctx context.Context, rawURL string) error

func CheckURL

func CheckURL(ctx context.Context, rawURL string) error

func DiscoverLiveWS

func DiscoverLiveWS(ctx context.Context) (string, error)

func DiscoverWSForProfile

func DiscoverWSForProfile(ctx context.Context, base string) (ws string, ok bool)

func SetDriver

func SetDriver(d string)

Types

type Backend

type Backend interface {
	Info(ctx context.Context) (PageInfo, error)

	Navigate(ctx context.Context, url string) error

	Back(ctx context.Context) error

	Eval(ctx context.Context, expression string) (string, error)

	ClickAt(ctx context.Context, x, y float64) error

	TypeText(ctx context.Context, text string) error

	PressKey(ctx context.Context, key string) error

	Fill(ctx context.Context, selector, text string) error

	Scroll(ctx context.Context, dy float64) error

	WaitLoad(ctx context.Context) error

	WaitElement(ctx context.Context, selector string, visible bool) (bool, error)

	Screenshot(ctx context.Context, maxDim int) (jpeg []byte, err error)

	AXTree(ctx context.Context) (string, error)

	BoxModel(ctx context.Context, backendNodeID int) (x, y float64, err error)

	Tabs(ctx context.Context) ([]Tab, error)

	UseTab(ctx context.Context, targetID string) error

	UploadFiles(ctx context.Context, selector string, paths []string) error

	Close() error

	Mode() Mode

	Obtained() Obtained

	HandleDialog(accept bool, promptText string) error
}

func Open

func Open(ctx context.Context, mode Mode) (Backend, error)

func OpenNamed

func OpenNamed(ctx context.Context, mode Mode, sessionName string) (Backend, error)

type Browser

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

func (*Browser) AXTree

func (b *Browser) AXTree(ctx context.Context) (string, error)

func (*Browser) Back

func (b *Browser) Back(ctx context.Context) error

func (*Browser) BoxModel

func (b *Browser) BoxModel(ctx context.Context, backendNodeID int) (float64, float64, error)

func (*Browser) ClickAt

func (b *Browser) ClickAt(ctx context.Context, x, y float64) error

func (*Browser) Close

func (b *Browser) Close() error

func (*Browser) Eval

func (b *Browser) Eval(ctx context.Context, expression string) (string, error)

func (*Browser) Fill

func (b *Browser) Fill(ctx context.Context, selector, text string) error

func (*Browser) HandleDialog

func (b *Browser) HandleDialog(accept bool, promptText string) error

func (*Browser) Info

func (b *Browser) Info(ctx context.Context) (PageInfo, error)

func (*Browser) Mode

func (b *Browser) Mode() Mode

func (*Browser) Navigate

func (b *Browser) Navigate(ctx context.Context, url string) error

func (*Browser) Obtained

func (b *Browser) Obtained() Obtained

func (*Browser) PressKey

func (b *Browser) PressKey(ctx context.Context, key string) error

func (*Browser) Screenshot

func (b *Browser) Screenshot(ctx context.Context, maxDim int) ([]byte, error)

func (*Browser) Scroll

func (b *Browser) Scroll(ctx context.Context, dy float64) error

func (*Browser) Tabs

func (b *Browser) Tabs(ctx context.Context) ([]Tab, error)

func (*Browser) TypeText

func (b *Browser) TypeText(ctx context.Context, text string) error

func (*Browser) UploadFiles

func (b *Browser) UploadFiles(ctx context.Context, selector string, paths []string) error

func (*Browser) UseTab

func (b *Browser) UseTab(ctx context.Context, targetID string) error

func (*Browser) WaitElement

func (b *Browser) WaitElement(ctx context.Context, selector string, visible bool) (bool, error)

func (*Browser) WaitLoad

func (b *Browser) WaitLoad(ctx context.Context) error

type Dialog

type Dialog struct {
	Type, Message, DefaultPrompt string
}

type Manager

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

func NewManager

func NewManager(mode Mode) *Manager

func (*Manager) CloseAll

func (m *Manager) CloseAll()

func (*Manager) Session

func (m *Manager) Session(name string) (*Session, error)

func (*Manager) SwitchDriver

func (m *Manager) SwitchDriver(d string)

type Mode

type Mode string
const (
	ModeLive Mode = "live"

	ModeDedicated Mode = "dedicated"

	ModeHeadless Mode = "headless"

	ModeExtension Mode = "extension"
)

type Obtained

type Obtained int
const (
	ObtainedLive Obtained = iota
	ObtainedLaunched
	ObtainedReattached
)

type PageInfo

type PageInfo struct {
	URL, Title            string
	Width, Height         int
	ScrollX, ScrollY      float64
	PageWidth, PageHeight float64
	Dialog                *Dialog `json:",omitempty"`
}

type Session

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

func (*Session) Do

func (s *Session) Do(ctx context.Context, fn func(b Backend) (string, error)) (string, error)

type Tab

type Tab struct {
	TargetID, Title, URL string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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