Documentation
¶
Overview ¶
Package release performs optional, isolated browser work outside the fast build.
Index ¶
- Constants
- Variables
- func AuditHandler(page []byte, assets map[string][]byte, origin string) http.Handler
- func BrowserOptions(path string) []chromedp.ExecAllocatorOption
- func BrowserPath() (string, error)
- func CacheKey(ctx context.Context, target Target, root string) string
- func FramesPath(root string) string
- func Handler(page []byte, assets map[string][]byte) http.Handler
- func LighthouseDiagnostics(lh *LighthouseResult) []diagnostic.Diagnostic
- func ReadCache(key string, value any) time.Time
- func ReportPath(root string) string
- func WriteCache(key string, value any)
- type AuditFinding
- type AuditResult
- type Delivery
- type LayoutFinding
- type LayoutResult
- type LighthouseResult
- type Placement
- type Printer
- func (p *Printer) BookLayout(doc []byte, assets map[string][]byte, columnInches float64) ([]string, error)
- func (p *Printer) Close()
- func (p *Printer) Overflows(doc []byte, assets map[string][]byte, width, height int64) ([]string, error)
- func (p *Printer) PageImages(doc []byte, assets map[string][]byte, width, height int64, scale float64, ...) ([][]byte, error)
- func (p *Printer) PageLayout(doc []byte, assets map[string][]byte, width, height int64, safe float64) ([]string, error)
- func (p *Printer) Picture(doc []byte, assets map[string][]byte, width, height int64, scale float64) ([]byte, error)
- func (p *Printer) Print(doc []byte, assets map[string][]byte, outline bool) ([]byte, error)
- type Result
- type RuntimeResult
- type Screen
- type Target
- type Viewport
Constants ¶
const BrowserSetup = "" /* 146-byte string literal not displayed */
const LighthouseSetup = "" /* 176-byte string literal not displayed */
const LocalPortSetup = "" /* 172-byte string literal not displayed */
LocalPortSetup explains how to let Chrome load pages from lfm.
Variables ¶
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.
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 ¶
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 CacheKey ¶ added in v0.1.10
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
FramesPath is the screenshot folder of a project, in the user cache directory like the Lighthouse report, so the project tree stays clean.
func LighthouseDiagnostics ¶
func LighthouseDiagnostics(lh *LighthouseResult) []diagnostic.Diagnostic
func ReportPath ¶
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
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:"-"`
}
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
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) 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.
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
}
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.