Skip to content

pog7x/ssfactory

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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