browser

package
v0.0.0-...-72c2bb7 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2020 License: MIT Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const SOCK = "/tmp/leaser.sock"

Variables

View Source
var (
	ErrNavigationTimedOut = errors.New("navigation timed out")
	ErrTabCrashed         = errors.New("tab crashed")
	ErrTabClosing         = errors.New("closing")
	ErrTimedOut           = errors.New("request timed out")
	ErrNavigating         = errors.New("error in navigation")
)
View Source
var (
	ErrBrowserClosing = errors.New("unable to load, as closing down")
)

Functions

func KillOldProcesses

func KillOldProcesses() error

func RemoveTmpContents

func RemoveTmpContents() error

Types

type Browser

type Browser interface {
	LoadForDiff(ctx context.Context, address *am.ScanGroupAddress, scheme, port string) (url, dom string, err error)
	// Load a web page, return the dom string, responses
	Load(ctx context.Context, address *am.ScanGroupAddress, scheme, port string) (webData *am.WebData, err error)
}

type GCDBrowserPool

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

func NewGCDBrowserPool

func NewGCDBrowserPool(maxBrowsers int, leaser LeaserService, techDetect webtech.Detector) *GCDBrowserPool

func (*GCDBrowserPool) Acquire

func (b *GCDBrowserPool) Acquire(ctx context.Context) *gcd.Gcd

Acquire a Browser, unless context expired. If expired, increment our Browser error count which is used to restart the entire browser process after a max limit on errors is reached

func (*GCDBrowserPool) Close

func (b *GCDBrowserPool) Close(ctx context.Context) error

Close all browsers and return. TODO: make this not terrible.

func (*GCDBrowserPool) Init

func (b *GCDBrowserPool) Init() error

Init starts the browser/Browser pool

func (*GCDBrowserPool) Load

func (b *GCDBrowserPool) Load(ctx context.Context, address *am.ScanGroupAddress, scheme, port string) (*am.WebData, error)

Load an address of scheme and port, returning an image, the dom, all text based responses or an error.

func (*GCDBrowserPool) LoadForDiff

func (b *GCDBrowserPool) LoadForDiff(ctx context.Context, address *am.ScanGroupAddress, scheme, port string) (string, string, error)

func (*GCDBrowserPool) Return

func (b *GCDBrowserPool) Return(ctx context.Context, browser *gcd.Gcd, startCount int32)

Return a browser

func (*GCDBrowserPool) SetAPITimeout

func (b *GCDBrowserPool) SetAPITimeout(duration time.Duration)

SetAPITimeout tells gcd how long to wait for a response from the browser for all API calls

func (*GCDBrowserPool) Start

func (b *GCDBrowserPool) Start() error

Start the browser with a random profile directory and create Browsers

func (*GCDBrowserPool) UseDisplay

func (b *GCDBrowserPool) UseDisplay(display string)

UseDisplay (to be called before Init()) tells chrome to start using an Xvfb display

type GcdLeaser

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

func NewGcdLeaser

func NewGcdLeaser() *GcdLeaser

func (*GcdLeaser) Acquire

func (g *GcdLeaser) Acquire(w http.ResponseWriter, r *http.Request)

func (*GcdLeaser) Cleanup

func (g *GcdLeaser) Cleanup(w http.ResponseWriter, r *http.Request)

func (*GcdLeaser) Count

func (g *GcdLeaser) Count(w http.ResponseWriter, r *http.Request)

func (*GcdLeaser) ForceKill

func (g *GcdLeaser) ForceKill(pid int)

func (*GcdLeaser) Return

func (g *GcdLeaser) Return(w http.ResponseWriter, r *http.Request)

func (*GcdLeaser) Serve

func (g *GcdLeaser) Serve() error

func (*GcdLeaser) Shutdown

func (g *GcdLeaser) Shutdown()

type LeaserService

type LeaserService interface {
	Acquire() (string, error) // returns port number
	Return(port string) error
	Cleanup() (string, error)
	Count() (string, error)
}

type LocalLeaser

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

func NewLocalLeaser

func NewLocalLeaser() *LocalLeaser

func (*LocalLeaser) Acquire

func (s *LocalLeaser) Acquire() (string, error)

func (*LocalLeaser) Cleanup

func (s *LocalLeaser) Cleanup() (string, error)

func (*LocalLeaser) Count

func (s *LocalLeaser) Count() (string, error)

func (*LocalLeaser) Return

func (s *LocalLeaser) Return(port string) error

type ResponseContainer

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

func NewResponseContainer

func NewResponseContainer() *ResponseContainer

func (*ResponseContainer) Add

func (c *ResponseContainer) Add(response *am.HTTPResponse)

Add a response to our map

func (*ResponseContainer) BodyReady

func (c *ResponseContainer) BodyReady(requestID string)

BodyReady signals WaitFor that the response is done, and we can start reading the body

func (*ResponseContainer) DecRequest

func (c *ResponseContainer) DecRequest()

func (*ResponseContainer) GetRequests

func (c *ResponseContainer) GetRequests() int32

func (*ResponseContainer) GetResponses

func (c *ResponseContainer) GetResponses() (*am.HTTPResponse, []*am.HTTPResponse)

GetResponses returns the main load reseponse and all responses then clears the container

func (*ResponseContainer) IncRequest

func (c *ResponseContainer) IncRequest()

func (*ResponseContainer) SetLoadRequest

func (c *ResponseContainer) SetLoadRequest(requestID string)

SetLoadRequest uses the requestID of the *first* request as our key to return the httpresponse in GetResponses.

func (*ResponseContainer) WaitFor

func (c *ResponseContainer) WaitFor(ctx context.Context, requestID string) error

WaitFor see if we have a readyCh for this request, if we don't, make the channel if we do, it is already closed so we can return

type SocketLeaser

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

func NewSocketLeaser

func NewSocketLeaser() *SocketLeaser

func (*SocketLeaser) Acquire

func (s *SocketLeaser) Acquire() (string, error)

func (*SocketLeaser) Cleanup

func (s *SocketLeaser) Cleanup() (string, error)

func (*SocketLeaser) Count

func (s *SocketLeaser) Count() (string, error)

func (*SocketLeaser) Return

func (s *SocketLeaser) Return(port string) error

type Tab

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

func NewTab

func NewTab(ctx context.Context, tab *gcd.ChromeTarget, address *am.ScanGroupAddress) *Tab

func (*Tab) CaptureNetworkTraffic

func (t *Tab) CaptureNetworkTraffic(ctx context.Context, address *am.ScanGroupAddress, port string)

CaptureNetworkTraffic ensures we capture all traffic (only saving text bodies) during navigation.

func (*Tab) Close

func (t *Tab) Close()

Close the exit channel

func (*Tab) GetNetworkTraffic

func (t *Tab) GetNetworkTraffic() (*am.HTTPResponse, []*am.HTTPResponse)

GetNetworkTraffic returns all responses after page load

func (*Tab) GetURL

func (t *Tab) GetURL(ctx context.Context) string

GetURL by looking at the navigation history

func (*Tab) InjectJS

func (t *Tab) InjectJS(inject string) (interface{}, error)

InjectJS only caller knows what the response type will be so return an interface{} caller must type check to whatever they expect

func (*Tab) LoadPage

func (t *Tab) LoadPage(ctx context.Context, url string) error

LoadPage capture network traffic and take screen shot of DOM and image

func (*Tab) SerializeDOM

func (t *Tab) SerializeDOM() string

SerializeDOM and return it as string

func (*Tab) TakeScreenshot

func (t *Tab) TakeScreenshot(ctx context.Context) (string, error)

TakeScreenshot returns a png image, base64 encoded, or error if failed

func (*Tab) WaitReady

func (t *Tab) WaitReady(ctx context.Context, stableAfter time.Duration) error

WaitReady waits for the page to load, DOM to be stable, and no network traffic in progress

Jump to

Keyboard shortcuts

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