Documentation
¶
Index ¶
- Constants
- Variables
- func KillOldProcesses() error
- func RemoveTmpContents() error
- type Browser
- type GCDBrowserPool
- func (b *GCDBrowserPool) Acquire(ctx context.Context) *gcd.Gcd
- func (b *GCDBrowserPool) Close(ctx context.Context) error
- func (b *GCDBrowserPool) Init() error
- func (b *GCDBrowserPool) Load(ctx context.Context, address *am.ScanGroupAddress, scheme, port string) (*am.WebData, error)
- func (b *GCDBrowserPool) LoadForDiff(ctx context.Context, address *am.ScanGroupAddress, scheme, port string) (string, string, error)
- func (b *GCDBrowserPool) Return(ctx context.Context, browser *gcd.Gcd, startCount int32)
- func (b *GCDBrowserPool) SetAPITimeout(duration time.Duration)
- func (b *GCDBrowserPool) Start() error
- func (b *GCDBrowserPool) UseDisplay(display string)
- type GcdLeaser
- func (g *GcdLeaser) Acquire(w http.ResponseWriter, r *http.Request)
- func (g *GcdLeaser) Cleanup(w http.ResponseWriter, r *http.Request)
- func (g *GcdLeaser) Count(w http.ResponseWriter, r *http.Request)
- func (g *GcdLeaser) ForceKill(pid int)
- func (g *GcdLeaser) Return(w http.ResponseWriter, r *http.Request)
- func (g *GcdLeaser) Serve() error
- func (g *GcdLeaser) Shutdown()
- type LeaserService
- type LocalLeaser
- type ResponseContainer
- func (c *ResponseContainer) Add(response *am.HTTPResponse)
- func (c *ResponseContainer) BodyReady(requestID string)
- func (c *ResponseContainer) DecRequest()
- func (c *ResponseContainer) GetRequests() int32
- func (c *ResponseContainer) GetResponses() (*am.HTTPResponse, []*am.HTTPResponse)
- func (c *ResponseContainer) IncRequest()
- func (c *ResponseContainer) SetLoadRequest(requestID string)
- func (c *ResponseContainer) WaitFor(ctx context.Context, requestID string) error
- type SocketLeaser
- type Tab
- func (t *Tab) CaptureNetworkTraffic(ctx context.Context, address *am.ScanGroupAddress, port string)
- func (t *Tab) Close()
- func (t *Tab) GetNetworkTraffic() (*am.HTTPResponse, []*am.HTTPResponse)
- func (t *Tab) GetURL(ctx context.Context) string
- func (t *Tab) InjectJS(inject string) (interface{}, error)
- func (t *Tab) LoadPage(ctx context.Context, url string) error
- func (t *Tab) SerializeDOM() string
- func (t *Tab) TakeScreenshot(ctx context.Context) (string, error)
- func (t *Tab) WaitReady(ctx context.Context, stableAfter time.Duration) error
Constants ¶
const SOCK = "/tmp/leaser.sock"
Variables ¶
var ( ErrTabCrashed = errors.New("tab crashed") ErrTabClosing = errors.New("closing") ErrTimedOut = errors.New("request timed out") )
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) 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
type LeaserService ¶
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.
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 ¶
CaptureNetworkTraffic ensures we capture all traffic (only saving text bodies) during navigation.
func (*Tab) GetNetworkTraffic ¶
func (t *Tab) GetNetworkTraffic() (*am.HTTPResponse, []*am.HTTPResponse)
GetNetworkTraffic returns all responses after page load
func (*Tab) InjectJS ¶
InjectJS only caller knows what the response type will be so return an interface{} caller must type check to whatever they expect
func (*Tab) TakeScreenshot ¶
TakeScreenshot returns a png image, base64 encoded, or error if failed