browser

package
v0.9.43 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2018 License: MIT Imports: 37 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 DefaultReplyTimeout = 30 * time.Second
View Source
var DefaultStartWait = time.Duration(500) * time.Millisecond
View Source
var ElementPollTimeout = time.Second
View Source
var ExitRequested = errors.New(`exit requested`)
View Source
var MaxUnreadEvents = 1024
View Source
var ProcessExitCheckInterval = 125 * time.Millisecond
View Source
var ProcessExitMaxWait = 10 * time.Second

Functions

func IsElementNotFoundErr

func IsElementNotFoundErr(err error) bool

func IsExitRequestedErr added in v0.9.27

func IsExitRequestedErr(err error) bool

func LocateChromeExecutable

func LocateChromeExecutable() string

func TooManyMatchesErr

func TooManyMatchesErr(selector Selector, want int, have int) error

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"`
	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:"-"`
	// contains filtered or unexported fields
}

func NewBrowser

func NewBrowser() *Browser

func Start

func Start() (*Browser, error)

func (*Browser) ElementsFromSelector added in v0.9.31

func (self *Browser) ElementsFromSelector(selector interface{}) ([]*Element, bool, error)

func (*Browser) GetReaderForPath added in v0.9.33

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

func (*Browser) GetWriterForPath

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

func (*Browser) Launch

func (self *Browser) Launch() error

func (*Browser) RegisterPathHandler

func (self *Browser) RegisterPathHandler(handler PathHandlerFunc)

func (*Browser) RegisterPathReader added in v0.9.33

func (self *Browser) RegisterPathReader(handler PathReaderFunc)

func (*Browser) SetScope

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

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 Dimensions

type Dimensions struct {
	Width  int `json:"width"`
	Height int `json:"height"`
	Top    int `json:"top"`
	Left   int `json:"left"`
	Right  int `json:"right"`
	Bottom int `json:"bottom"`
}

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 Document

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

func NewDocument

func NewDocument(tab *Tab, parent *Document) *Document

func (*Document) Element

func (self *Document) Element(id int) (*Element, bool)

Retrieve a known element by its Node ID

func (*Document) ElementByNodeID added in v0.9.29

func (self *Document) ElementByNodeID(id int) (*Element, bool)

Retrieve a known element by its Node ID

func (*Document) ElementsByName added in v0.9.28

func (self *Document) ElementsByName(name string) []*Element

Retrieve all elements matching the given name

func (*Document) Evaluate

func (self *Document) Evaluate(stmt string) (interface{}, error)

func (*Document) EvaluateOn

func (self *Document) EvaluateOn(selector Selector, stmt string) (interface{}, error)

func (*Document) HighlightAll

func (self *Document) HighlightAll(selector Selector) error

Highlight all nodes matching the given selector.

func (*Document) PageSize

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

Retrieve the current document's dimensions (scroll width and height).

func (*Document) PrintTree

func (self *Document) PrintTree()

Recursively print the entire document tree, retrieving elements as neccessary.

func (*Document) Query

func (self *Document) Query(selector Selector, queryRoot *Element) ([]*Element, error)

Select one or more elements from the current DOM.

func (*Document) RemoveElement

func (self *Document) RemoveElement(element *Element) error

Remove the given element from the document.

func (*Document) Reset

func (self *Document) Reset()

func (*Document) Root

func (self *Document) Root() (*Element, error)

Return the root element of the current document.

func (*Document) String

func (self *Document) String() string

type Element

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

func (*Element) Attributes

func (self *Element) Attributes() map[string]interface{}

Retrieve the current attributes on the element.

func (*Element) BackendID added in v0.9.29

func (self *Element) BackendID() int

func (*Element) Click

func (self *Element) Click() error

Click on the current element.

func (*Element) Evaluate

func (self *Element) Evaluate(script string) (interface{}, error)

Evaluate the given JavaScript as an anonymous function on the current element.

func (*Element) Focus

func (self *Element) Focus() error

Focus the current element.

func (*Element) Highlight

func (self *Element) Highlight(r int, g int, b int, a float64) error

func (*Element) MarshalJSON

func (self *Element) MarshalJSON() ([]byte, error)

func (*Element) Name added in v0.9.28

func (self *Element) Name() string

Retrieve the name of the element.

func (*Element) NodeID added in v0.9.29

func (self *Element) NodeID() int

func (*Element) Position

func (self *Element) Position() (Dimensions, error)

Retrieve the current position and dimensions of the element.

func (*Element) Remove

func (self *Element) Remove() error

Remove the element.

func (*Element) SetAttribute

func (self *Element) SetAttribute(attrName string, value interface{}) error

Set the given named attribute to the stringified output of value.

func (*Element) String

func (self *Element) String() string

Satisifies the fmt.Stringer interface.

func (*Element) Text

func (self *Element) Text() string

Retrieve the text value of the element.

func (*Element) ToMap

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

func (*Element) TreeString

func (self *Element) TreeString(depth int) string

Prints this element and all subelements.

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 added in v0.9.33

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

type NetworkInterceptResponse added in v0.9.33

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 added in v0.9.33

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

type NetworkRequest added in v0.9.24

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

func (*NetworkRequest) Error added in v0.9.24

func (self *NetworkRequest) Error() error

func (*NetworkRequest) IsCompleted added in v0.9.24

func (self *NetworkRequest) IsCompleted() bool

func (*NetworkRequest) R added in v0.9.24

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

type NetworkRequestPattern added in v0.9.33

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

func (*NetworkRequestPattern) ToMap added in v0.9.33

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 added in v0.9.33

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 Selector

type Selector string

func (Selector) GetAnnotation

func (self Selector) GetAnnotation() (string, string, error)

func (Selector) IsAnnotated

func (self Selector) IsAnnotated() bool

func (Selector) IsNone

func (self Selector) IsNone() bool

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 added in v0.9.33

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 added in v0.9.33

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) DOM

func (self *Tab) DOM() *Document

func (*Tab) Disconnect

func (self *Tab) Disconnect() error

func (*Tab) Emit

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

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) 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