browser

package
v1.10.0 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2023 License: MIT Imports: 47 Imported by: 1

Documentation

Index

Constants

View Source
const (
	Left   Button = `left`
	Middle        = `middle`
	Right         = `right`
)
View Source
const (
	Pressed  MouseAction = `mousePressed`
	Released             = `mouseReleased`
	Moved                = `mouseMoved`
	Scrolled             = `mouseWheel`
)
View Source
const (
	KeyPressed  KeyboardAction = `keyDown`
	KeyReleased                = `keyUp`
	KeyRaw                     = `rawKeyDown`
)

Variables

View Source
var ContainerInspectTimeout = 3 * time.Second
View Source
var DebuggerInnerPort = 9222
View Source
var DefaultContainerMemory = `512m`
View Source
var DefaultContainerRuntime = `docker`
View Source
var DefaultContainerSharedMemory = `256m`
View Source
var DefaultContainerTargetAddr = `localhost`
View Source
var DefaultDebuggingPort = 0 // 0 = allocate an ephemeral port
View Source
var DefaultReplyTimeout = 30 * time.Second
View Source
var DefaultStartURL = `about:blank`
View Source
var DefaultStartWait = 10 * time.Second
View Source
var DefaultUserDirPath = `/var/tmp`
View Source
var ExitRequested = errors.New(`exit requested`)
View Source
var MaxUnreadEvents = 1024
View Source
var NotImplemented = errors.New(`Not Implemented`)
View Source
var ProcessExitCheckInterval = 125 * time.Millisecond
View Source
var ProcessExitMaxWait = 10 * time.Second

Functions

func IsExitRequestedErr

func IsExitRequestedErr(err error) bool

func IsNotImplementedErr

func IsNotImplementedErr(err error) bool

func LocateChromeExecutable

func LocateChromeExecutable() string

func StopAllActiveBrowsers

func StopAllActiveBrowsers()

Types

type BookmarkBarPreferences

type BookmarkBarPreferences struct {
	ShowOnAllTabs bool `json:"show_on_all_tabs"`
}

type Browser

type Browser struct {
	Command                     argonaut.CommandName   `argonaut:",joiner=[=]"`
	App                         string                 `argonaut:"app,long"`
	DisableGPU                  bool                   `argonaut:"disable-gpu,long"`
	HideScrollbars              bool                   `argonaut:"hide-scrollbars,long"`
	Headless                    bool                   `argonaut:"headless,long"`
	Kiosk                       bool                   `argonaut:"kiosk,long"`
	ProxyBypassList             []string               `argonaut:"proxy-bypass-list,long,delimiters=[;]"`
	ProxyServer                 string                 `argonaut:"proxy-server,long"`
	RemoteDebuggingPort         int                    `argonaut:"remote-debugging-port,long"`
	RemoteDebuggingAddress      string                 `argonaut:"remote-debugging-address,long"`
	UserDataDirectory           string                 `argonaut:"user-data-dir,long"`
	DefaultBackgroundColor      string                 `argonaut:"default-background-color,long"`
	DisableSessionCrashedBubble bool                   `argonaut:"disable-session-crashed-bubble,long"`
	DisableInfobars             bool                   `argonaut:"disable-infobars,long"`
	SingleProcess               bool                   `argonaut:"single-process,long"`
	DisableSharedMemory         bool                   `argonaut:"disable-dev-shm-usage,long"`
	DisableSetuidSandbox        bool                   `argonaut:"disable-setuid-sandbox,long"`
	NoZygote                    bool                   `argonaut:"no-zygote,long"`
	NoSandbox                   bool                   `argonaut:"no-sandbox,long"`
	UserAgent                   string                 `argonaut:"user-agent,long"`
	URL                         string                 `argonaut:",positional"`
	StartWait                   time.Duration          `argonaut:"-"`
	Environment                 map[string]interface{} `argonaut:"-"`
	Directory                   string                 `argonaut:"-"`
	Preferences                 *Preferences           `argonaut:"-"`
	Container                   Container              `argonaut:"-"`
	ID                          string                 `argonaut:"-"`
	RemoteAddress               string
	// contains filtered or unexported fields
}

func NewBrowser

func NewBrowser() *Browser

func Start

func Start() (*Browser, error)

func (*Browser) GetReaderForPath

func (self *Browser) GetReaderForPath(path string) (io.ReadCloser, error)

func (*Browser) GetWriterForPath

func (self *Browser) GetWriterForPath(path string) (string, io.Writer, bool)

func (*Browser) IsConnected

func (self *Browser) IsConnected() bool

func (*Browser) Launch

func (self *Browser) Launch() error

func (*Browser) RegisterPathHandler

func (self *Browser) RegisterPathHandler(handler PathHandlerFunc)

func (*Browser) RegisterPathReader

func (self *Browser) RegisterPathReader(handler PathReaderFunc)

func (*Browser) SetScope

func (self *Browser) SetScope(scopeable utils.Runtime)

func (*Browser) Stop

func (self *Browser) Stop() error

func (*Browser) Tab

func (self *Browser) Tab() *Tab

func (*Browser) Wait

func (self *Browser) Wait() error

type BrowserPreferences

type BrowserPreferences struct {
	ShowHomeButton                    bool     `json:"show_home_button"`
	CheckDefaultBrowser               bool     `json:"check_default_browser"`
	DefaultBrowserInfobarLastDeclined string   `json:"default_browser_infobar_last_declined"`
	EnabledLabsExperiments            []string `json:"enabled_labs_experiments,omitempty"`
}

type Button

type Button string

func (Button) String

func (self Button) String() string

type Container

type Container interface {
	Start() error
	Config() *ContainerConfig
	Validate() error
	Address() string
	IsRunning() bool
	Stop() error
	ID() string
	String() string
}

type ContainerConfig

type ContainerConfig struct {
	Hostname     string
	Namespace    string
	Name         string
	User         string
	Env          []string
	Cmd          []string
	ImageName    string
	Memory       string
	SharedMemory string
	Ports        []string
	Volumes      []string
	Labels       map[string]string
	Privileged   bool
	WorkingDir   string
	UserDirPath  string
	TargetAddr   string
}

func (*ContainerConfig) AddPort

func (self *ContainerConfig) AddPort(outer int, inner int, proto string)

func (*ContainerConfig) SetTargetPort

func (self *ContainerConfig) SetTargetPort(port int) string

func (*ContainerConfig) Validate

func (self *ContainerConfig) Validate() error

type DistributionPreferences

type DistributionPreferences struct {
	DoNotCreateAnyShortcuts              bool   `json:"do_not_create_any_shortcuts"`
	DoNotCreateDesktopShortcut           bool   `json:"do_not_create_desktop_shortcut"`
	DoNotCreateQuickLaunchShortcut       bool   `json:"do_not_create_quick_launch_shortcut"`
	DoNotCreateTaskbarShortcut           bool   `json:"do_not_create_taskbar_shortcut"`
	DoNotLaunchChrome                    bool   `json:"do_not_launch_chrome"`
	DoNotRegisterForUpdateLaunch         bool   `json:"do_not_register_for_update_launch"`
	ImportBookmarks                      bool   `json:"import_bookmarks"`
	ImportBookmarksFromFile              string `json:"import_bookmarks_from_file,omitempty"`
	ImportHistory                        bool   `json:"import_history"`
	ImportHomePage                       bool   `json:"import_home_page"`
	ImportSearchEngine                   bool   `json:"import_search_engine"`
	MakeChromeDefault                    bool   `json:"make_chrome_default"`
	MakeChromeDefaultForUser             bool   `json:"make_chrome_default_for_user"`
	PingDelay                            int    `json:"ping_delay,omitempty"`
	RequireEula                          bool   `json:"require_eula"`
	SuppressFirstRunBubble               bool   `json:"suppress_first_run_bubble"`
	SuppressFirstRunDefaultBrowserPrompt bool   `json:"suppress_first_run_default_browser_prompt"`
	SystemLevel                          bool   `json:"system_level"`
	VerboseLogging                       bool   `json:"verbose_logging"`
}

type DockerContainer

type DockerContainer struct {
	*ContainerConfig
	// contains filtered or unexported fields
}

func NewDockerContainer

func NewDockerContainer(url string) *DockerContainer

func (*DockerContainer) Address

func (self *DockerContainer) Address() string

func (*DockerContainer) Config

func (self *DockerContainer) Config() *ContainerConfig

func (*DockerContainer) ID

func (self *DockerContainer) ID() string

func (*DockerContainer) IsRunning

func (self *DockerContainer) IsRunning() bool

func (*DockerContainer) Start

func (self *DockerContainer) Start() error

func (*DockerContainer) Stop

func (self *DockerContainer) Stop() error

func (*DockerContainer) String

func (self *DockerContainer) String() string

func (*DockerContainer) Validate

func (self *DockerContainer) Validate() error

type Event

type Event struct {
	ID        int
	Name      string
	Result    *maputil.Map
	Params    *maputil.Map
	Error     error
	Timestamp time.Time
}

func (*Event) P

func (self *Event) P() *maputil.Map

func (*Event) R

func (self *Event) R() *maputil.Map

func (*Event) String

func (self *Event) String() string

type EventCallbackFunc

type EventCallbackFunc func(event *Event)

type EventWaiter

type EventWaiter struct {
	Pattern glob.Glob
	Events  chan *Event
	// contains filtered or unexported fields
}

func NewEventWaiter

func NewEventWaiter(tab *Tab, eventGlob string) (*EventWaiter, error)

func (*EventWaiter) Match

func (self *EventWaiter) Match(event *Event) bool

func (*EventWaiter) Remove

func (self *EventWaiter) Remove()

func (*EventWaiter) Wait

func (self *EventWaiter) Wait(timeout time.Duration) (*Event, error)

type KeyboardAction

type KeyboardAction string

func (KeyboardAction) String

func (self KeyboardAction) String() string

type KeyboardActionConfig

type KeyboardActionConfig struct {
	Action  KeyboardAction `json:"action" default:"keyDown"`
	Alt     bool           `json:"alt,omitempty"`
	Control bool           `json:"control,omitempty"`
	Meta    bool           `json:"meta,omitempty"`
	Shift   bool           `json:"shift,omitempty"`
	KeyCode int            `json:"keycode,omitempty"`
}

type MouseAction

type MouseAction string

func (MouseAction) String

func (self MouseAction) String() string

type MouseActionConfig

type MouseActionConfig struct {
	Action  MouseAction `json:"action" default:"mouseMoved"`
	Button  Button      `json:"button,omitempty"`
	Alt     bool        `json:"alt,omitempty"`
	Control bool        `json:"control,omitempty"`
	Meta    bool        `json:"meta,omitempty"`
	Shift   bool        `json:"shift,omitempty"`
	WheelX  float64     `json:"wheelX,omitempty"`
	WheelY  float64     `json:"wheelY,omitempty"`
	Count   int         `json:"count,omitempty"`
}

type NetworkInterceptFunc

type NetworkInterceptFunc func(*Tab, *NetworkRequestPattern, *Event) *NetworkInterceptResponse

type NetworkInterceptResponse

type NetworkInterceptResponse struct {
	URL          string
	Method       string
	Body         io.Reader
	PostData     map[string]interface{}
	Header       http.Header
	Error        error
	AuthResponse string
	Username     string
	Password     string
	Autoremove   bool
}

func (*NetworkInterceptResponse) ToMap

func (self *NetworkInterceptResponse) ToMap(id string) map[string]interface{}

type NetworkRequest

type NetworkRequest struct {
	ID         string
	Request    *Event
	Response   *Event
	Failure    *Event
	Completion *Event
}

func (*NetworkRequest) Error

func (self *NetworkRequest) Error() error

func (*NetworkRequest) IsCompleted

func (self *NetworkRequest) IsCompleted() bool

func (*NetworkRequest) R

func (self *NetworkRequest) R() *maputil.Map

type NetworkRequestPattern

type NetworkRequestPattern struct {
	URL               string
	ResourceType      string
	InterceptionStage string
	Pattern           glob.Glob
}

func (*NetworkRequestPattern) ToMap

func (self *NetworkRequestPattern) ToMap() map[string]interface{}

type PageInfo

type PageInfo struct {
	URL   string `json:"url"`
	State string `json:"state"`
	// contains filtered or unexported fields
}

type PathHandlerFunc

type PathHandlerFunc = func(string) (string, io.Writer, bool)

type PathReaderFunc

type PathReaderFunc = func(string) (io.ReadCloser, bool)

type Preferences

type Preferences struct {
	Homepage             string                   `json:"homepage"`
	HomepageIsNewTabPage bool                     `json:"homepage_is_newtabpage"`
	Browser              *BrowserPreferences      `json:"browser,omitempty"`
	Session              *SessionPreferences      `json:"session,omitempty"`
	BookmarkBar          *BookmarkBarPreferences  `json:"bookmark_bar,omitempty"`
	SyncPromo            *SyncPromoPreferences    `json:"sync_promo,omitempty"`
	Distribution         *DistributionPreferences `json:"distribution,omitempty"`
	FirstRunTabs         []string                 `json:"first_run_tabs,omitempty"`
}

func GetDefaultPreferences

func GetDefaultPreferences() *Preferences

type RPC

type RPC struct {
	URL string
	// contains filtered or unexported fields
}

func NewRPC

func NewRPC(wsUrl string) (*RPC, error)

func (*RPC) Call

func (self *RPC) Call(method string, params map[string]interface{}, timeout time.Duration) (*RpcMessage, error)

func (*RPC) CallAsync

func (self *RPC) CallAsync(method string, params map[string]interface{}) error

func (*RPC) Close

func (self *RPC) Close() error

func (*RPC) Messages

func (self *RPC) Messages() <-chan *RpcMessage

func (*RPC) Send

func (self *RPC) Send(message *RpcMessage, timeout time.Duration) (*RpcMessage, error)

func (*RPC) SynthesizeEvent

func (self *RPC) SynthesizeEvent(message RpcMessage)

type RpcError

type RpcError struct {
	Code    int
	Message string
}

func (*RpcError) Error

func (self *RpcError) Error() string

type RpcMessage

type RpcMessage struct {
	ID     int64                  `json:"id"`
	Method string                 `json:"method"`
	Params map[string]interface{} `json:"params,omitempty"`
	Result map[string]interface{} `json:"result,omitempty"`
	Error  map[string]interface{} `json:"error,omitempty"`
}

func (*RpcMessage) P

func (self *RpcMessage) P() *maputil.Map

func (*RpcMessage) R

func (self *RpcMessage) R() *maputil.Map

func (*RpcMessage) String

func (self *RpcMessage) String() string

type SessionPreferences

type SessionPreferences struct {
	RestoreOnStartup int      `json:"restore_on_startup"`
	StartupUrls      []string `json:"startup_urls,omitempty"`
}

type SyncPromoPreferences

type SyncPromoPreferences struct {
	ShowOnFirstRunAllowed bool `json:"show_on_first_run_allowed"`
}

type Tab

type Tab struct {
	AfterCommandDelay time.Duration
	// contains filtered or unexported fields
}

func (*Tab) AddNetworkIntercept

func (self *Tab) AddNetworkIntercept(urlPattern string, waitForHeaders bool, fn NetworkInterceptFunc) error

func (*Tab) AsyncRPC

func (self *Tab) AsyncRPC(module string, method string, args map[string]interface{}) error

func (*Tab) ClearNetworkIntercepts

func (self *Tab) ClearNetworkIntercepts() error

func (*Tab) CreateAccumulator

func (self *Tab) CreateAccumulator(filter string) (*eventAccumulator, error)

func (*Tab) CreateEventWaiter

func (self *Tab) CreateEventWaiter(eventGlob string) (*EventWaiter, error)

func (*Tab) Disconnect

func (self *Tab) Disconnect() error

func (*Tab) ElementPosition

func (self *Tab) ElementPosition(element *dom.Element) (dom.Dimensions, error)

func (*Tab) ElementQuery

func (self *Tab) ElementQuery(selector dom.Selector, parent *dom.Selector) ([]*dom.Element, error)

func (*Tab) Emit

func (self *Tab) Emit(method string, params map[string]interface{})

func (*Tab) Evaluate

func (self *Tab) Evaluate(stmt string, exposed ...string) (interface{}, error)

func (*Tab) EvaluateOn

func (self *Tab) EvaluateOn(element *dom.Element, stmt string, exposed ...string) (interface{}, error)

func (*Tab) GetLoaderRequest

func (self *Tab) GetLoaderRequest(id string) (netreq *NetworkRequest)

func (*Tab) GetMostRecentFrame

func (self *Tab) GetMostRecentFrame() (int64, []byte, int, int)

func (*Tab) ID

func (self *Tab) ID() string

func (*Tab) Info

func (self *Tab) Info() *PageInfo

func (*Tab) IsScreencasting

func (self *Tab) IsScreencasting() bool

func (*Tab) MoveMouse

func (self *Tab) MoveMouse(x float64, y float64, config *MouseActionConfig) error

func (*Tab) Navigate

func (self *Tab) Navigate(url string) (*RpcMessage, error)

func (*Tab) PageSize

func (self *Tab) PageSize() (float64, float64, error)

func (*Tab) RPC

func (self *Tab) RPC(module string, method string, args map[string]interface{}) (*RpcMessage, error)

func (*Tab) RegisterEventHandler

func (self *Tab) RegisterEventHandler(eventGlob string, callback EventCallbackFunc) (string, error)

func (*Tab) RemoveWaiter

func (self *Tab) RemoveWaiter(id string)

func (*Tab) ResetMostRecentFrame

func (self *Tab) ResetMostRecentFrame()

func (*Tab) ResetNetworkRequests

func (self *Tab) ResetNetworkRequests()

func (*Tab) SendKey

func (self *Tab) SendKey(domKeyName string, config *KeyboardActionConfig) error

func (*Tab) StartScreencast

func (self *Tab) StartScreencast(quality int, width int, height int) error

func (*Tab) StopScreencast

func (self *Tab) StopScreencast() error

func (*Tab) WaitFor

func (self *Tab) WaitFor(eventGlob string, timeout time.Duration) (*Event, error)

type TabID

type TabID string

Jump to

Keyboard shortcuts

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