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) 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.