ssfactory

package module
v0.0.0-...-e2ba8bf Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2023 License: MIT Imports: 6 Imported by: 1

README

ssfactory (screenshot factory)

GoDoc Build Status License

Example of factory initialization and making screenshot

package main

import "github.com/pog7x/ssfactory"

func someActionsOnBytes(screenshotBytes []byte) error {
	// Some actions on bytes (encode to png, send via http/rmq etc.)
	return nil
}

func main() {
	f, stopFunc, err := ssfactory.NewFactory(
		ssfactory.InitFactory{
			WebdriverPort:     8080,
			UseBrowser:        "firefox",
			FirefoxBinaryPath: "/usr/bin/firefox",
			GeckodriverPath:   "./dependencies/geckodriver",
			FirefoxArgs: []string{
				"--headless",
				"--no-sandbox",
				"--disable-dev-shm-usage",
				"--width=1920",
			},
		},
	)
	if err != nil {
		panic("initialization screenshot factory error")
	}

	defer stopFunc()

	var maximize string

	f.MakeScreenshot(
		ssfactory.MakeScreenshotPayload{
			URL:            "https://github.com",
			DOMElementBy:   ssfactory.ByTagName,
			DOMElementName: "body",
			Scroll:         true,
			BytesHandler:   someActionsOnBytes,
			MaximizeWindow: &maximize,
		},
	)
}

Documentation

Index

Constants

View Source
const (
	FirefoxName = "firefox"
	ChromeName  = "chrome"
)
View Source
const (
	ByID              = "id"
	ByXPATH           = "xpath"
	ByLinkText        = "link text"
	ByPartialLinkText = "partial link text"
	ByName            = "name"
	ByTagName         = "tag name"
	ByClassName       = "class name"
	ByCSSSelector     = "css selector"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Factory

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

func NewFactory

func NewFactory(init InitFactory) (*Factory, func(), error)

func (*Factory) MakeScreenshot

func (f *Factory) MakeScreenshot(p MakeScreenshotPayload)

type InitFactory

type InitFactory struct {
	WebdriverPort uint16

	UseBrowser string

	FirefoxBinaryPath string
	FirefoxArgs       []string
	GeckodriverPath   string

	ChromeBinaryPath string
	ChromeArgs       []string
	ChromedriverPath string

	WorkersCount int
}

type MakeScreenshotPayload

type MakeScreenshotPayload struct {
	URL            string
	DOMElementBy   string
	DOMElementName string
	Scroll         bool
	MaximizeWindow *string
	Timeout        time.Duration
	BytesHandler   bytesHandler
}

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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