ssfactory

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

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

Go to latest
Published: Mar 4, 2026 License: MIT Imports: 6 Imported by: 1

README

ssfactory

Go Reference Build Status

Concurrent screenshot capture library for Go, powered by Selenium WebDriver and a built-in worker pool.

Features

  • Browser support — Chrome (via ChromeDriver) and Firefox (via GeckoDriver)
  • Concurrency — built-in worker pool for parallel screenshot jobs
  • Element targeting — capture specific DOM elements by ID, XPath, CSS selector, tag name, etc.
  • Flexible output — raw []byte passed to your handler (save to disk, upload, encode — up to you)

Prerequisites

Dependency Purpose
ChromeDriver or GeckoDriver Browser automation driver
Chrome or Firefox Target browser binary

Installation

go get github.com/pog7x/ssfactory

Quick Start

package main

import "github.com/pog7x/ssfactory"

func main() {
	f, stop, err := ssfactory.NewFactory(ssfactory.InitFactory{
		WebdriverPort:     9515,
		UseBrowser:        ssfactory.ChromeName,
		ChromeBinaryPath:  "/usr/bin/google-chrome",
		ChromedriverPath:  "/usr/local/bin/chromedriver",
		ChromeArgs:        []string{"--headless", "--no-sandbox", "--disable-dev-shm-usage"},
		WorkersCount:      4,
	})
	if err != nil {
		panic(err)
	}
	defer stop()

	maximize := ""
	f.MakeScreenshot(ssfactory.MakeScreenshotPayload{
		URL:            "https://example.com",
		DOMElementBy:   ssfactory.ByTagName,
		DOMElementName: "body",
		Scroll:         true,
		MaximizeWindow: &maximize,
		BytesHandler: func(b []byte) error {
			// save, upload, encode to PNG, etc.
			return nil
		},
	})
}
Firefox example
f, stop, err := ssfactory.NewFactory(ssfactory.InitFactory{
	WebdriverPort:     8080,
	UseBrowser:        ssfactory.FirefoxName,
	FirefoxBinaryPath: "/usr/bin/firefox",
	GeckodriverPath:   "/usr/local/bin/geckodriver",
	FirefoxArgs:       []string{"--headless", "--width=1920"},
	WorkersCount:      2,
})

API

Element selectors
Constant Selenium strategy
ByID id
ByXPATH xpath
ByLinkText link text
ByPartialLinkText partial link text
ByName name
ByTagName tag name
ByClassName class name
ByCSSSelector css selector
MakeScreenshotPayload
Field Type Description
URL string Page URL to navigate to
DOMElementBy string Selector strategy (see table above)
DOMElementName string Selector value
Scroll bool Scroll element into view before capture
MaximizeWindow *string Maximize window handle (pass nil to skip)
Timeout time.Duration Wait timeout before capturing
BytesHandler func([]byte) error Callback receiving screenshot bytes

License

MIT — Copyright (c) 2022 pog7x

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