WebViewer

class WebViewer(pageSettleMillis: Long = DEFAULT_PAGE_SETTLE_MILLIS)(source)

Headless-Chrome screenshot utility.

getPage renders a URL in a throwaway headless Chrome instance and returns the capture as a PNG File; screenshot returns the same capture decoded into a BufferedImage. Both return a Result rather than throwing - a blank URL, a driver-launch failure, a navigation failure, or an image-decode failure all come back as Result.failure, matching the rest of WebTools.

The Chrome driver binary is resolved at runtime by Selenium Manager (bundled with Selenium since 4.6) - no driver is shipped in this artifact or configured by this class. Running a capture therefore needs a Chrome/Chromium install on the host, and outbound network access the first time a given driver version is downloaded.

Parameters

pageSettleMillis

how long to wait after navigation before capturing, so late-loading content has a chance to paint. This is a blunt fixed wait; a readiness-based wait (document.readyState) is an intended refinement. Defaults to DEFAULT_PAGE_SETTLE_MILLIS.

Constructors

Link copied to clipboard
constructor(pageSettleMillis: Long = DEFAULT_PAGE_SETTLE_MILLIS)

Types

Link copied to clipboard
object Companion

Holds DEFAULT_PAGE_SETTLE_MILLIS and the logger the instances share.

Functions

Link copied to clipboard
infix fun getPage(url: String): Result<File>

Renders url and writes the screenshot to a PNG file in the system temp directory.

Link copied to clipboard

Renders url and decodes the screenshot into an in-memory image.