Documentation
¶
Overview ¶
Package render provides the headless-rendering Fetcher backed by chromedp. It renders pages in a real Chromium tab, captures the post-JS DOM, records main-document redirects/status/headers via DevTools network events, and collects lab-mode Core Web Vitals (LCP, FCP, CLS, TBT, TTFB) using PerformanceObserver. On any rendering error the fetcher falls back to a raw HTTP fetch so a single broken page does not stall the crawl.
Headless mode requires a Chromium-class browser (Chrome, Chromium, or Edge) on PATH. NewHeadlessFetcher returns an error if no compatible browser can be launched.
Index ¶
Constants ¶
const LoginProfilePrefix = "gocrawl-login-"
LoginProfilePrefix is the temp-directory name prefix of a login window's throwaway browser profile; webserver.SweepStaleLoginProfiles recognizes leftovers by it.
Variables ¶
var ( // ErrNoBrowser means no Chromium-class browser is installed where gocrawl looks. ErrNoBrowser = errors.New("no Chromium-class browser found (install Google Chrome, Chromium or Microsoft Edge)") // ErrNoDisplay means a visible window can't open: no X11 or Wayland display. ErrNoDisplay = errors.New("no display for a browser window (DISPLAY and WAYLAND_DISPLAY are both unset)") // ErrLoginWindowClosed is returned by Cookies once the window is gone. ErrLoginWindowClosed = errors.New("the browser window was closed") )
Functions ¶
func FindBrowser ¶
FindBrowser returns the path of the first Chromium-class browser it finds, or ErrNoBrowser.
func LoginAvailable ¶
func LoginAvailable() error
LoginAvailable reports why OpenLoginWindow can't work on this machine, or nil when it can.
Types ¶
type HeadlessFetcher ¶
type HeadlessFetcher struct {
// contains filtered or unexported fields
}
HeadlessFetcher renders pages with chromedp and reports real Core Web Vitals.
func NewHeadlessFetcher ¶
func NewHeadlessFetcher(opts crawler.Options) (*HeadlessFetcher, error)
NewHeadlessFetcher launches the headless browser. It returns an error if no Chromium binary is available on PATH or the browser fails to start. Callers must Close() the fetcher when finished.
func (*HeadlessFetcher) Close ¶
func (h *HeadlessFetcher) Close() error
Close terminates the browser. Safe to call more than once.
type LoginWindow ¶
type LoginWindow struct {
// contains filtered or unexported fields
}
LoginWindow is a browser window opened for a person to log in to a site by hand, in a throwaway profile directory that Close deletes. gocrawl only reads its cookie jar.
func OpenLoginWindow ¶
func OpenLoginWindow(ctx context.Context, rawURL string) (*LoginWindow, error)
OpenLoginWindow starts a visible browser on rawURL. ctx bounds only the launch and the first navigation: the window stays open until Close, the person closes it, or the process exits.
func (*LoginWindow) Close ¶
func (w *LoginWindow) Close() error
Close stops the browser and deletes the throwaway profile. Safe to call more than once.
func (*LoginWindow) Cookies ¶
Cookies reads the browser's whole cookie jar over CDP, HttpOnly cookies and values included. Filtering to the site is the caller's job.
func (*LoginWindow) Done ¶
func (w *LoginWindow) Done() <-chan struct{}
Done is closed once the window is gone, by Close or by the person.