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

renderer

package
v0.12.8 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2026 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NeedsRendering

func NeedsRendering(mode DetectionMode, body []byte, staticData *parser.PageData) bool

NeedsRendering determines whether a page should be JS-rendered.

Types

type DetectionMode

type DetectionMode string

DetectionMode controls when JS rendering is applied.

const (
	ModeOff    DetectionMode = "off"
	ModeAuto   DetectionMode = "auto"
	ModeAlways DetectionMode = "always"
)

func ParseDetectionMode

func ParseDetectionMode(s string) DetectionMode

ParseDetectionMode converts a string to a DetectionMode.

type Pool

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

Pool manages a single Chrome browser with a pool of reusable pages.

func NewPool

func NewPool(opts PoolOptions) (*Pool, error)

NewPool launches a headless Chrome and creates a page pool.

func (*Pool) Acquire

func (p *Pool) Acquire() (*rod.Page, error)

Acquire returns a page from the pool or creates a new one.

func (*Pool) Close

func (p *Pool) Close()

Close shuts down the browser and all pages.

func (*Pool) Release

func (p *Pool) Release(page *rod.Page)

Release returns a page to the pool or closes it if the pool is full.

func (*Pool) Render

func (p *Pool) Render(ctx context.Context, url string) *RenderResult

Render navigates to the given URL in a headless Chrome page, waits for the page to stabilise, and returns the rendered HTML.

func (*Pool) RenderWithCWV added in v0.12.3

func (p *Pool) RenderWithCWV(ctx context.Context, url string) *RenderResult

RenderWithCWV is like Render but also measures Core Web Vitals (lab data). It does NOT block images (LCP depends on them) and uses the Chrome DevTools Protocol (PerformanceTimeline + Performance.getMetrics) instead of injected JS for reliable measurement:

  • TTFB: from Performance.getMetrics navigation timing
  • LCP: from PerformanceTimeline "largest-contentful-paint" events
  • CLS: from PerformanceTimeline "layout-shift" events

type PoolOptions

type PoolOptions struct {
	MaxPages       int
	PageTimeout    time.Duration
	UserAgent      string
	BlockResources bool
	Headless       bool
}

PoolOptions configures the Chrome page pool.

func DefaultPoolOptions

func DefaultPoolOptions() PoolOptions

type RenderResult

type RenderResult struct {
	RenderedHTML   string
	RenderDuration time.Duration
	JSErrors       []string
	Error          error

	// Core Web Vitals
	CWVMeasured bool
	CWVLCP      float64 // Largest Contentful Paint (ms)
	CWVCLS      float64 // Cumulative Layout Shift
	CWVTTFB     float64 // Time to First Byte (ms)
}

RenderResult holds the outcome of rendering a URL with Chrome.

Jump to

Keyboard shortcuts

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