screenshot

package module
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2022 License: GPL-3.0 Imports: 26 Imported by: 2

README

screenshot

Go Report Card Go Reference Releases

Screenshot is a project that capture and save webpage as image using chromedp.

This repository is a work in progress.

Prerequisite

  • Chrome/Chromium

Installation

From source:

go get github.com/wabarc/screenshot

From gobinaries.com:

curl -sf https://gobinaries.com/wabarc/screenshot | sh

From releases

Environments

  • CHROMEDP_DEBUG
  • CHROMEDP_NO_HEADLESS
  • CHROMEDP_NO_SANDBOX
  • CHROMEDP_DISABLE_GPU
  • CHROMEDP_USER_AGENT
  • CHROMEDP_STEALTH

Credits

License

This software is released under the terms of the GNU General Public License v3.0. See the LICENSE file for details.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type As added in v1.6.0

type As interface {
	Byte | Path
	String() string
}

type Byte added in v1.6.0

type Byte []byte

func (Byte) String added in v1.6.0

func (b Byte) String() string
type Cookie struct {
	Name      string    `yaml:"name"`                // Cookie name.
	Value     string    `yaml:"value"`               // Cookie value.
	Domain    string    `yaml:"domain"`              // Cookie domain.
	Path      string    `yaml:"path,omitempty"`      // Cookie path.
	Expires   time.Time `yaml:"expires,omitempty"`   // Cookie expiration date, session cookie if not set
	Size      int       `yaml:"size,omitempty"`      // Cookie size.
	HTTPOnly  bool      `yaml:"httpOnly,omitempty"`  // True if cookie is http-only.
	Secure    bool      `yaml:"secure,omitempty"`    // True if cookie is secure.
	SameSite  string    `yaml:"sameSite,omitempty"`  // Cookie SameSite type.
	SameParty bool      `yaml:"sameParty,omitempty"` // True if cookie is SameParty.
	Priority  string    `yaml:"priority,omitempty"`  // Cookie Priority type.
}

Cookie represents a cookie item.

func ImportCookies added in v1.4.0

func ImportCookies(r []byte) (cookies []Cookie, err error)

ImportCookies imports cookies by given byte with yaml configuration. Format: cookies:

example.com:
  - name: 'foo'
    value: 'bar'
  - name: 'zoo'
    value: 'zoo'
example.org:
  - name: 'foo'
    value: 'bar'

type Files added in v1.6.0

type Files struct {
	Image string
	HTML  string
	PDF   string
	HAR   string
}

type HAR added in v1.3.0

type HAR struct {
	Log hlog `json:"log,omitempty"`
}

type LocalStorage added in v1.4.0

type LocalStorage struct {
	Key   string
	Value string
	Host  string
}

LocalStorage represents a local storage item.

func ImportStorage added in v1.4.0

func ImportStorage(r []byte) (storage []LocalStorage, err error)

type Path added in v1.6.0

type Path string

func (Path) String added in v1.6.0

func (p Path) String() string

type ScreenshotOption

type ScreenshotOption func(*ScreenshotOptions)

func AppendToFile added in v1.6.0

func AppendToFile(f Files) ScreenshotOption

func Cookies added in v1.4.0

func Cookies(cookies []Cookie) ScreenshotOption

func DumpHAR added in v1.3.0

func DumpHAR(b bool) ScreenshotOption

func Format

func Format(format string) ScreenshotOption

func Height

func Height(height int64) ScreenshotOption

func MaxHeight

func MaxHeight(height int64) ScreenshotOption

func MaxWidth

func MaxWidth(width int64) ScreenshotOption

func Mobile

func Mobile(b bool) ScreenshotOption

func PrintPDF added in v1.2.0

func PrintPDF(b bool) ScreenshotOption

func Quality

func Quality(quality int64) ScreenshotOption

func RawHTML added in v1.2.0

func RawHTML(b bool) ScreenshotOption

func ScaleFactor

func ScaleFactor(factor float64) ScreenshotOption

func Storage added in v1.4.0

func Storage(storage []LocalStorage) ScreenshotOption

func Width

func Width(width int64) ScreenshotOption

type ScreenshotOptions

type ScreenshotOptions struct {
	Width  int64
	Height int64
	Mobile bool
	Format page.CaptureScreenshotFormat // jpg, png, default: png.

	Quality   int64
	MaxWidth  int64
	MaxHeight int64

	ScaleFactor float64

	PrintPDF bool
	RawHTML  bool
	DumpHAR  bool

	Files Files

	Cookies []Cookie
	Storage []LocalStorage
}

ScreenshotOptions is the options used by Screenshot.

type Screenshoter

type Screenshoter[T As] interface {
	Screenshot(ctx context.Context, input *url.URL, options ...ScreenshotOption) (*Screenshots[T], error)
}

Screenshoter is a webpage screenshot interface.

func NewChromeRemoteScreenshoter added in v1.1.0

func NewChromeRemoteScreenshoter[T As](addr string) (res Screenshoter[T], err error)

NewChromeRemoteScreenshoter creates a Screenshoter backed by Chrome DevTools Protocol. The addr is the headless chrome websocket debugger endpoint, such as 127.0.0.1:9222.

type Screenshots

type Screenshots[T As] struct {
	URL   string
	Title string
	Image T
	HTML  T
	PDF   T
	HAR   T

	// Total bytes of resources
	DataLength int64
}

func Screenshot

func Screenshot[T As](ctx context.Context, input *url.URL, options ...ScreenshotOption) (*Screenshots[T], error)

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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