Help us shape the future of Go! Take the 2026 Go Developer Survey

release

package
v0.1.14 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2026 License: MIT Imports: 46 Imported by: 0

Documentation

Overview

Package release performs optional, isolated browser work outside the fast build.

Index

Constants

View Source
const BrowserSetup = "" /* 146-byte string literal not displayed */
View Source
const LighthouseSetup = "" /* 176-byte string literal not displayed */
View Source
const LocalPortSetup = "" /* 172-byte string literal not displayed */

LocalPortSetup explains how to let Chrome load pages from lfm.

Variables

View Source
var ErrLocalPort = errors.New("no local port could be opened for Chrome to load the page from")

ErrLocalPort means no loopback port could be opened for Chrome to load from.

View Source
var Screens = []Screen{{390, 844, true}, {1280, 680, false}, {1440, 900, false}}

Screens are the sizes every page is reviewed at: a common phone, a short laptop screen and a desktop. Frames step by half a viewport, so every part of the page appears in two frames.

Functions

func AuditHandler

func AuditHandler(page []byte, assets map[string][]byte, origin string) http.Handler

AuditHandler serves only immutable in-memory artifact bytes, without invented delivery compression/cache/TLS advantages. Also suitable as Chrome's non-forwarding proxy.

func BrowserOptions added in v0.1.8

func BrowserOptions(path string) []chromedp.ExecAllocatorOption

BrowserOptions configures an isolated browser without background services.

func BrowserPath

func BrowserPath() (string, error)

func CacheKey added in v0.1.10

func CacheKey(ctx context.Context, target Target, root string) string

CacheKey includes the complete served artifact and the tools and settings that interpret it. Remote targets are mutable and cannot be cached.

func FramesPath added in v0.0.2

func FramesPath(root string) string

FramesPath is the screenshot folder of a project, in the user cache directory like the Lighthouse report, so the project tree stays clean.

func Handler

func Handler(page []byte, assets map[string][]byte) http.Handler

Handler exposes only the in-memory artifact, never project sources.

func LighthouseDiagnostics

func LighthouseDiagnostics(lh *LighthouseResult) []diagnostic.Diagnostic

func ReadCache added in v0.1.10

func ReadCache(key string, value any) time.Time

ReadCache treats absent, obsolete and corrupt files as misses.

func ReportPath

func ReportPath(root string) string

ReportPath is where the complete Lighthouse JSON of a project is kept: the user cache, outside the project and its deployable output.

func WriteCache added in v0.1.10

func WriteCache(key string, value any)

WriteCache is best effort and atomic. Keep at most 128 recent entries.

Types

type AuditFinding

type AuditFinding struct {
	ID         string   `json:"id"`
	Title      string   `json:"title"`
	Hint       string   `json:"hint"`
	Value      string   `json:"value,omitempty"`
	Categories []string `json:"scoredCategories,omitempty"`
	Score      *float64 `json:"score,omitempty"`
	Samples    []string `json:"samples,omitempty"`
	Items      int      `json:"detailItems,omitempty"`
}

type AuditResult

type AuditResult struct {
	Reused      string                  `json:"reusedFrom,omitempty"`
	Delivery    Delivery                `json:"delivery"`
	Runtime     *RuntimeResult          `json:"runtime,omitempty"`
	Lighthouse  *LighthouseResult       `json:"lighthouse"`
	Diagnostics []diagnostic.Diagnostic `json:"-"`
}

func Audit

func Audit(ctx context.Context, target Target, root string) *AuditResult

type Delivery added in v0.1.5

type Delivery struct {
	TextBytes       int `json:"textBytes"`       // HTML, CSS, scripts, SVG and data as built
	CompressedBytes int `json:"compressedBytes"` // the same with gzip, as hosts send them
	// UncompressedMS is about how much longer the text takes to arrive
	// uncompressed on Lighthouse's mobile network.
	UncompressedMS int `json:"uncompressedMs"`
}

Delivery is how the page's text travels: as hosts send it, compressed, and what leaving compression off would cost. Every common static host compresses text by default; the audit measures the page that way.

type LayoutFinding added in v0.0.2

type LayoutFinding struct {
	Screen  string `json:"viewport"`
	Kind    string `json:"kind"` // overflow, empty, split
	Message string `json:"message"`
	Hint    string `json:"hint"`
}

LayoutFinding is one layout defect at one viewport.

type LayoutResult added in v0.0.2

type LayoutResult struct {
	Frames   string          `json:"frames,omitempty"` // folder of the frame screenshots
	Count    int             `json:"count"`
	Previous bool            `json:"previous"`          // a former run left frames to compare with
	Changed  []string        `json:"changed,omitempty"` // frames that differ from the former run, without .jpg
	Findings []LayoutFinding `json:"findings,omitempty"`
}

LayoutResult is what the frame walk found.

type LighthouseResult

type LighthouseResult struct {
	Runs       int               `json:"runs,omitempty"`
	Info       []AuditFinding    `json:"diagnostics,omitempty"`
	ThirdParty []AuditFinding    `json:"thirdParty,omitempty"`
	Status     string            `json:"status"`
	Reason     string            `json:"reason,omitempty"`
	Hint       string            `json:"hint,omitempty"`
	Missing    bool              `json:"missing,omitempty"` // executable not installed
	Version    string            `json:"version,omitempty"`
	Chrome     string            `json:"chrome,omitempty"`
	Scope      string            `json:"scope"`
	Report     string            `json:"report,omitempty"`
	DurationMS int64             `json:"durationMs"`
	Scores     map[string]*int   `json:"scores,omitempty"`
	Metrics    map[string]string `json:"metrics,omitempty"`
	Findings   []AuditFinding    `json:"findings,omitempty"`
	Manual     []AuditFinding    `json:"manualChecks,omitempty"`
	Host       []AuditFinding    `json:"hostChecks,omitempty"` // delivery the host decides, not the page
	Warnings   []string          `json:"warnings,omitempty"`
	// contains filtered or unexported fields
}

type Placement added in v0.0.2

type Placement struct {
	Src         string  `json:"src"`
	FirstScreen bool    `json:"firstScreen"` // visible before scrolling at any reviewed size
	PhoneArea   float64 `json:"phoneArea"`   // visible area in the phone's first screen, CSS px²
}

Placement is where one <img> renders, in document order.

func ImagePlacement added in v0.0.2

func ImagePlacement(ctx context.Context, page []byte, assets map[string][]byte) ([]Placement, error)

ImagePlacement renders the page with scripts blocked at the critical-CSS sizes and reports for every image whether it shows before scrolling. The compiler uses it to fill missing loading and fetch-priority hints.

type Printer added in v0.0.3

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

Printer prints documents (books, printables) in one Chrome, a tab per job, so a release pays for one browser start however many PDFs it prints. It is safe for concurrent use.

func NewPrinter added in v0.0.3

func NewPrinter(ctx context.Context) (*Printer, error)

NewPrinter starts Chrome. Close it when the release is done.

func (*Printer) BookLayout added in v0.0.3

func (p *Printer) BookLayout(doc []byte, assets map[string][]byte, columnInches float64) ([]string, error)

BookLayout loads a book document at phone width and at the width of the printed text column and reports what does not fit: elements wider than the column, clipped images, images split across printed pages and text below 9 pixels.

func (*Printer) Close added in v0.0.3

func (p *Printer) Close()

Close stops Chrome.

func (*Printer) Overflows added in v0.1.0

func (p *Printer) Overflows(doc []byte, assets map[string][]byte, width, height int64) ([]string, error)

Overflows loads a document in print media and names the data-fit value of every element whose content does not fit inside it, each once: text a box would cut off or spill.

func (*Printer) PageImages added in v0.1.0

func (p *Printer) PageImages(doc []byte, assets map[string][]byte, width, height int64, scale float64, pages []int) ([][]byte, error)

PageImages renders pages (1-based) of a document of .page sections as PNGs at scale device pixels per CSS pixel.

func (*Printer) PageLayout added in v0.1.0

func (p *Printer) PageLayout(doc []byte, assets map[string][]byte, width, height int64, safe float64) ([]string, error)

PageLayout loads a document of fixed-size .page sections in print media and reports, per page, content that overflows the page or reaches into the safe margin of safe CSS pixels: text, images, SVG and canvas outside the inset, unless inside an element marked data-bleed.

func (*Printer) Picture added in v0.1.0

func (p *Printer) Picture(doc []byte, assets map[string][]byte, width, height int64, scale float64) ([]byte, error)

Picture renders a document at width×height CSS pixels and scale as a PNG of the viewport.

func (*Printer) Print added in v0.0.3

func (p *Printer) Print(doc []byte, assets map[string][]byte, outline bool) ([]byte, error)

Print prints a document to PDF at the page size its @page rule declares, with bookmarks from its headings when outline is set. Fonts and images are awaited first so no fallback face is baked in.

type Result

type Result struct {
	Applied       bool         `json:"applied"`
	Reason        string       `json:"reason,omitempty"`
	OriginalBytes int          `json:"originalCSSBytes"`
	CriticalBytes int          `json:"criticalCSSBytes"`
	Stylesheet    string       `json:"stylesheet,omitempty"`
	Selection     string       `json:"selection,omitempty"`
	Viewports     []Viewport   `json:"viewports,omitempty"`
	CSS           string       `json:"-"`
	Audit         *AuditResult `json:"audit,omitempty"`
	LazyImages    int          `json:"lazyImages,omitempty"`    // images the compiler set to load lazily
	PriorityImage string       `json:"priorityImage,omitempty"` // image the compiler set to fetch first
}

func Analyze

func Analyze(ctx context.Context, page []byte, assets map[string][]byte) (Result, error)

Analyze observes static first paint at several widths, unions visible rules, then verifies both critical-only and critical+full rendering at every width. The original full CSS is never purged. Ambiguous/unstable pages retain it inline.

type RuntimeResult

type RuntimeResult struct {
	Status     string        `json:"status"`
	Reason     string        `json:"reason,omitempty"`
	Hint       string        `json:"hint,omitempty"`
	Chrome     string        `json:"chrome,omitempty"`
	Scope      string        `json:"scope,omitempty"`
	Problems   []string      `json:"problems,omitempty"`
	Layout     *LayoutResult `json:"layout,omitempty"`
	DurationMS int64         `json:"durationMs"`
}

func AuditRuntime

func AuditRuntime(ctx context.Context, target Target, path, frames string) *RuntimeResult

AuditRuntime is a cheap real-JS navigation probe that also runs when Lighthouse isn't installed. It never guesses which business controls to click or submits forms/orders. The same tab then walks the page frame by frame at every review screen (auditLayout); frames is the screenshot folder, "" for none.

type Screen added in v0.0.2

type Screen struct {
	Width, Height int
	Mobile        bool
}

Screen is one screen size of the continuum review.

func (Screen) String added in v0.0.2

func (v Screen) String() string

type Target added in v0.1.8

type Target struct {
	URL    string
	Page   []byte
	Assets map[string][]byte
}

Target selects a live URL or immutable artifact bytes for browser checks.

type Viewport

type Viewport struct {
	Width  int64 `json:"width"`
	Height int64 `json:"height"`
}

Jump to

Keyboard shortcuts

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