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
  • Constructor Details

    • AbstractScreenshotHandler

      protected AbstractScreenshotHandler()
    • AbstractScreenshotHandler

      protected AbstractScreenshotHandler(CachedStreamFactory streamFactory)
  • Method Details

    • captureScreenshotBytes

      protected abstract byte[] captureScreenshotBytes(T source) throws Exception
      Captures screenshot bytes for the given browser source. Implementations are responsible for applying CSS selector-based element targeting (when ScreenshotHandlerConfig.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

      public void takeScreenshot(T source, Doc doc)
      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 object
      doc - the crawl document to attach the image to
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • canEqual

      protected boolean canEqual(Object other)
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • getConfiguration

      public ScreenshotHandlerConfig getConfiguration()
      Specified by:
      getConfiguration in interface Configurable<T>