Class AbstractScreenshotHandler<T>
java.lang.Object
com.norconex.crawler.web.fetch.util.AbstractScreenshotHandler<T>
- Type Parameters:
T- the browser driver/page type used to capture the screenshot
- All Implemented Interfaces:
Configurable<ScreenshotHandlerConfig>
- Direct Known Subclasses:
PlaywrightScreenshotHandler,WebDriverScreenshotHandler
public abstract class AbstractScreenshotHandler<T>
extends Object
implements Configurable<ScreenshotHandlerConfig>
Base class for screenshot handlers that capture browser page images during
crawling. Handles the common infrastructure: stream management,
DocImageHandler wiring, and error handling.
Concrete subclasses implement captureScreenshotBytes(Object) to
obtain the raw screenshot bytes using their specific browser API (e.g.,
Selenium WebDriver or Playwright). CSS selector-based element targeting,
when supported, should also be applied within that method.
- Since:
- 4.0.0
-
Field Summary
Fields inherited from interface com.norconex.commons.lang.config.Configurable
PROPERTY -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedprotectedAbstractScreenshotHandler(CachedStreamFactory streamFactory) -
Method Summary
Modifier and TypeMethodDescriptionprotected booleanprotected abstract byte[]captureScreenshotBytes(T source) Captures screenshot bytes for the given browser source.booleaninthashCode()voidtakeScreenshot(T source, Doc doc) Takes a screenshot of the given browser source and stores it according to the handler configuration.toString()
-
Constructor Details
-
AbstractScreenshotHandler
protected AbstractScreenshotHandler() -
AbstractScreenshotHandler
-
-
Method Details
-
captureScreenshotBytes
Captures screenshot bytes for the given browser source. Implementations are responsible for applying CSS selector-based element targeting (whenScreenshotHandlerConfig.getCssSelector()is set) before returning the final image bytes.- Parameters:
source- the browser driver or page object- Returns:
- screenshot bytes (PNG or JPEG)
- Throws:
Exception- if the screenshot cannot be captured
-
takeScreenshot
Takes a screenshot of the given browser source and stores it according to the handler configuration. Exceptions during capture are logged but not propagated.- Parameters:
source- the browser driver or page objectdoc- the crawl document to attach the image to
-
toString
-
equals
-
canEqual
-
hashCode
public int hashCode() -
getConfiguration
- Specified by:
getConfigurationin interfaceConfigurable<T>
-