screenit

package module
v0.0.0-...-696b9f2 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2023 License: MIT Imports: 12 Imported by: 0

README

screenit

A Golang library and CLI tool for capturing web page screenshots with configurable options.

Installation

Go
go install github.com/root4loot/screenit/cmd/screenit@latest
Docker
git clone https://github.com/root4loot/screenit.git && cd screenit
docker build -t screenit .
docker run -it screenit -h

Usage

Usage:   ./screenit [options] (-u <url> | -i <urls.txt>)


INPUT:
   -u,   --url      target URL
   -i,   --infile   file containing URLs

CONFIGURATIONS:
   -c,   --concurrency        number of concurrent requests   (Default: 10)
   -t,   --timeout            screenshot timeout              (Default: 15 seconds)
   -ua,  --user-agent         set user agent                  (Default: Chrome Headless)
   -su,  --save-unique        save unique screenshots only    (Default: false)
   -wb,  --wait-for-body      wait for page body to load      (Default: true)
   -ice, --ignore-cert-err    ignore certificate errors       (Default: true)
   -dh,  --disable-http2      disable HTTP2                   (Default: true)
   -fr,  --follow-redirects   follow redirects                (Default: true)
   -cw,  --capture-width      screenshot pixel width          (Default: 1024)
   -ch,  --capture-height     screenshot pixel height         (Default: 768)

OUTPUT:
   -o,  --outfolder           save images to given folder     (Default: ./screenshots)
   -s,  --silence             silence output
   -v,  --verbose             verbose output

Example running

Running against list of URL's and waiting for HTML BODY to fully render before capturing screenshot:

✗ screenit -i urls.txt --wait-for-body
[SCREENIT] (INFO) Screenshot http://example.com saved to ./screenshots                                                                                           
[SCREENIT] (INFO) Screenshot https://example.com saved to ./screenshots                                                                                          
[SCREENIT] (INFO) Screenshot http://hackerone.com saved to ./screenshots                                                                                         
[SCREENIT] (INFO) Screenshot https://hackerone.com saved to ./screenshots                                                                                        
[SCREENIT] (INFO) Screenshot http://google.com saved to ./screenshots                                                                                            
[SCREENIT] (INFO) Screenshot http://bugcrowd.com saved to ./screenshots                                                                                          
[SCREENIT] (INFO) Screenshot https://bugcrowd.com saved to ./screenshots                                                                                         
[SCREENIT] (INFO) Screenshot https://google.com saved to ./screenshots                                                                                           
[SCREENIT] (INFO) Screenshot https://facebook.com saved to ./screenshots                                                                                         
[SCREENIT] (INFO) Screenshot http://facebook.com saved to ./screenshots                                                                                          
[SCREENIT] (INFO) Screenshot http://yahoo.com saved to ./screenshots                                                                                             
[SCREENIT] (INFO) Screenshot https://yahoo.com saved to ./screenshots                                                                                            
[SCREENIT] (INFO) Screenshot http://github.com saved to ./screenshots                                                                                            
[SCREENIT] (INFO) Screenshot https://github.com saved to ./screenshots                                                                                           
[SCREENIT] (WARNING) Timeout exceeded for http://tesla.com                                                                                                       
[SCREENIT] (WARNING) Timeout exceeded for https://tesla.com     

URL's may also be piped / streamed to STDIN:

✗ screenit cat urls.txt | go run cmd/screenit/* -v                                     
[SCREENIT] (INFO) Screenshot http://example.com saved to ./screenshots
[SCREENIT] (INFO) Screenshot https://example.com saved to ./screenshots
[SCREENIT] (INFO) Screenshot http://example.com saved to ./screenshots
[SCREENIT] (INFO) Screenshot https://example.com saved to ./screenshots
[SCREENIT] (INFO) Screenshot http://hackerone.com saved to ./screenshots
[SCREENIT] (INFO) Screenshot https://hackerone.com saved to ./screenshots
[SCREENIT] (INFO) Screenshot http://hackerone.com saved to ./screenshots
[SCREENIT] (INFO) Screenshot https://hackerone.com saved to ./screenshots
[SCREENIT] (INFO) Screenshot https://google.com saved to ./screenshots
[SCREENIT] (INFO) Screenshot http://google.com saved to ./screenshots
[SCREENIT] (INFO) Screenshot http://bugcrowd.com saved to ./screenshots
[SCREENIT] (INFO) Screenshot https://bugcrowd.com saved to ./screenshots

As lib

go get github.com/root4loot/screenit
package main

import (
	"fmt"

	"github.com/root4loot/screenit"
)

func main() {

	// List of URLs to capture
	urls := []string{
		"https://example.com",
		"https://hackerone.com",
		"https://bugcrowd.com",
		"https://google.com",
		"https://facebook.com",
		"https://yahoo.com",
		"https://tesla.com",
		"https://github.com",
	}

	// Set options
	options := screenit.Options{
		Concurrency:             10,
		Timeout:                 15,
		SaveScreenshots:         true,
		WaitForPageBody:         false,
		FollowRedirects:         true,
		DisableHTTP2:            true,
		IgnoreCertificateErrors: true,
		Verbose:                 false,
		Silence:                 true,
	}

	// Create a screenit runner with options
	runner := screenit.NewRunnerWithOptions(options)

	// Create a channel to receive results
	results := make(chan screenit.Result)

	// Start capturing URLs using multiple goroutines
	go runner.MultipleStream(results, urls...)

	// Process the results as they come in
	for result := range results {
		fmt.Println(result.URL, result.Error, len(result.Image))
	}
}

For more, see examples

License

See LICENSE

Contributing

See CONTRIBUTING.md

Documentation

Index

Constants

View Source
const Version = "0.0.0"

Variables

View Source
var Log = relog.NewLogger("screenit")

Functions

This section is empty.

Types

type Options

type Options struct {
	Concurrency             int            // number of concurrent requests
	CaptureHeight           int            // height of the capture
	CaptureWidth            int            // width of the capture
	Timeout                 int            // Timeout for each capture (seconds)
	IgnoreCertificateErrors bool           // Ignore certificate errors
	DisableHTTP2            bool           // Disable HTTP2
	SaveScreenshots         bool           // Save screenshot to file
	SaveScreenshotsPath     string         // Path to save screenshots
	SaveUnique              bool           // Save unique screenshots only
	Scope                   *goscope.Scope // Scope to use
	UserAgent               string         // User agent to use
	WaitForPageBody         bool           // Wait for page body to load
	// Resolvers               []string       // List of resolvers to use
	FollowRedirects bool // Follow redirects
	Silence         bool // Silence output
	Verbose         bool // Verbose logging
}

Options contains options for the runner

func DefaultOptions

func DefaultOptions() *Options

DefaultOptions returns default options

type Result

type Result struct {
	URL      string
	Image    []byte
	Resolver string
	Error    error
}

func Single

func Single(target string) (result Result)

Single captures a single target and returns the result

func (Result) WriteToFolder

func (result Result) WriteToFolder(folderPath string) (filename string, err error)

type Runner

type Runner struct {
	Options *Options
}

func NewRunner

func NewRunner() *Runner

NewRunner returns a new runner

func NewRunnerWithOptions

func NewRunnerWithOptions(options Options) *Runner

NewRunnerWithOptions returns a new runner with the specified options

func (*Runner) GetCustomFlags

func (r *Runner) GetCustomFlags() []chromedp.ExecAllocatorOption

getCustomFlags returns custom chromedp.ExecAllocatorOptions based on the Runner's Options.

func (*Runner) Multiple

func (r *Runner) Multiple(targets []string) (results []Result)

Multiple captures multiple targets and returns the results

func (*Runner) MultipleStream

func (r *Runner) MultipleStream(results chan<- Result, targets ...string)

MultipleStream captures multiple targets and streams the results using channels

Directories

Path Synopsis
cmd
examples

Jump to

Keyboard shortcuts

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