Interface CrawlEventHandlers
-
- All Implemented Interfaces:
public interface CrawlEventHandlersEvent handlers during the browser phase of the webpage lifecycle.
Crawl event handlers are triggered at the beginning and end of the browser iteration, wrapping around the load and browse phases. They are ideal for:
Filtering or modifying URLs before processing
Handling browser results after page loading
Implementing browser-level logic (e.g., rate limiting, deduplication)
browser.onWillLoad → [Load Phase] → [Browse Phase] → browser.onLoadedcrawlEventHandlers.apply { onWillLoad.addLast { url: UrlAware -> // Filter or modify URL before loading if (url.url.contains("skip-this")) null else url } onLoaded.addLast { url, page -> // Process results after loading println("Loaded: ${url.url}, success: ${page != null}") } }
-
-
Method Summary
Modifier and Type Method Description abstract CrawlEventHandlerschain(CrawlEventHandlers other)Chains another browser event handler to the tail of this one. abstract UrlAwareEventHandlergetOnWillLoad()Fires when the URL is about to be loaded in the Main loop. abstract UrlAwareWebPageEventHandlergetOnLoaded()Fires when the URL has been loaded in the Main loop. -
-
Method Detail
-
chain
abstract CrawlEventHandlers chain(CrawlEventHandlers other)
Chains another browser event handler to the tail of this one.
Chained handlers execute in order: this handler's callbacks run first, then the other handler's callbacks.
- Parameters:
other- The browser event handlers to chain- Returns:
This handler instance for fluent chaining
-
getOnWillLoad
abstract UrlAwareEventHandler getOnWillLoad()
Fires when the URL is about to be loaded in the Main loop.
This is the first event in the page lifecycle. Use this handler to:
Filter URLs (return
nullto skip)Modify URL properties before loading
Log or track browser progress
(UrlAware) -> UrlAware?onWillLoad.addLast { url: UrlAware -> if (isBlacklisted(url.url)) null else url }- Returns:
The URL to continue processing, or
nullto skip this URL
-
getOnLoaded
abstract UrlAwareWebPageEventHandler getOnLoaded()
Fires when the URL has been loaded in the Main loop.
This is the last event in the page lifecycle. Use this handler to:
Process loaded page content
Handle load failures (page will be
null)Collect statistics or metrics
(UrlAware, WebPage?) -> Any?onLoaded.addLast { url, page -> if (page != null) { saveToDatabase(page) } else { logFailure(url) } }
-
-
-
-