Interface BrowseEventHandlers
-
- All Implemented Interfaces:
public interface BrowseEventHandlersEvent handlers during the browsing phase of the webpage lifecycle.
Browse event handlers control browser automation operations including navigation, scrolling, waiting, and custom RPA (Robotic Process Automation) actions. All handlers receive both a WebPage and WebDriver for full browser control.
onWillLaunchBrowser → onBrowserLaunched → onWillFetch → onWillNavigate → onNavigated → onWillInteract → onWillCheckDocumentState → onDocumentFullyLoaded → onWillScroll → onDidScroll → onDocumentSteady → onWillComputeFeature → onFeatureComputed → onDidInteract → onWillStopTab → onTabStopped → onFetchedonDocumentSteady: Best event for custom RPA actions (clicks, form fills)
onBrowserLaunched: Ideal for browser initialization and warm-up
onNavigated: Good for waiting for specific content after navigation
browseEventHandlers.apply { onBrowserLaunched.addLast { page, driver -> driver.addInitScript("console.log('Initialized')") } onDocumentSteady.addLast { page, driver -> driver.click("button.load-more") driver.waitForSelector(".new-content") } }
-
-
Method Summary
Modifier and Type Method Description abstract BrowseEventHandlerschain(BrowseEventHandlers other)Chains another browse event handler to the tail of this one. abstract WebPageEventHandlergetOnWillLaunchBrowser()Fires when the browser is about to be launched. abstract WebPageWebDriverEventHandlergetOnBrowserLaunched()Fires when the browser has been launched. abstract WebPageWebDriverEventHandlergetOnWillFetch()Fires when the URL is about to be fetched via browser. abstract WebPageWebDriverEventHandlergetOnFetched()Fires when the URL has been fetched via browser. abstract WebPageWebDriverEventHandlergetOnWillNavigate()Fires when the URL is about to be navigated. abstract WebPageWebDriverEventHandlergetOnNavigated()Fires when navigation is complete. abstract WebPageWebDriverEventHandlergetOnWillInteract()Fires when interaction with the webpage is about to begin. abstract WebPageWebDriverEventHandlergetOnDidInteract()Fires when all interactions with the webpage have completed. abstract WebPageWebDriverEventHandlergetOnWillCheckDocumentState()Fires when the document state is about to be checked. abstract WebPageWebDriverEventHandlergetOnDocumentFullyLoaded()Fires when the document is fully loaded. abstract WebPageWebDriverEventHandlergetOnWillScroll()Fires when page scrolling is about to begin. abstract WebPageWebDriverEventHandlergetOnDidScroll()Fires when page scrolling has completed. abstract WebPageWebDriverEventHandlergetOnDocumentSteady()Fires when the document is steady and ready for custom actions. abstract WebPageWebDriverEventHandlergetOnWillComputeFeature()Fires when webpage features are about to be computed. abstract WebPageWebDriverEventHandlergetOnFeatureComputed()Fires when webpage features have been computed. abstract WebPageWebDriverEventHandlergetOnWillStopTab()Fires when the browser tab is about to be stopped. abstract WebPageWebDriverEventHandlergetOnTabStopped()Fires when the browser tab has been stopped. -
-
Method Detail
-
chain
abstract BrowseEventHandlers chain(BrowseEventHandlers other)
Chains another browse event handler to the tail of this one.
- Parameters:
other- The browse event handlers to chain- Returns:
This handler instance for fluent chaining
-
getOnWillLaunchBrowser
abstract WebPageEventHandler getOnWillLaunchBrowser()
Fires when the browser is about to be launched.
This event occurs before any browser instance is started. Use for pre-launch preparation.
(WebPage) -> Any?
-
getOnBrowserLaunched
abstract WebPageWebDriverEventHandler getOnBrowserLaunched()
Fires when the browser has been launched.
This is the first event where WebDriver is available. Ideal for browser initialization, adding scripts, or warming up.
suspend (WebPage, WebDriver) -> Any?onBrowserLaunched.addLast { page, driver -> driver.addInitScript("window.myConfig = { debug: true }") }
-
getOnWillFetch
abstract WebPageWebDriverEventHandler getOnWillFetch()
Fires when the URL is about to be fetched via browser.
This browse-phase fetch event occurs before navigation begins.
suspend (WebPage, WebDriver) -> Any?
-
getOnFetched
abstract WebPageWebDriverEventHandler getOnFetched()
Fires when the URL has been fetched via browser.
This browse-phase fetch event occurs after all browser interactions complete.
suspend (WebPage, WebDriver) -> Any?
-
getOnWillNavigate
abstract WebPageWebDriverEventHandler getOnWillNavigate()
Fires when the URL is about to be navigated.
This event occurs just before the browser navigates to the URL.
suspend (WebPage, WebDriver) -> Any?
-
getOnNavigated
abstract WebPageWebDriverEventHandler getOnNavigated()
Fires when navigation is complete.
Similar to clicking the "Go" button in the browser's navigation bar. The page has begun loading but may not be fully rendered.
suspend (WebPage, WebDriver) -> Any?onNavigated.addLast { page, driver -> driver.waitForSelector(".main-content", timeout = 10_000) }
-
getOnWillInteract
abstract WebPageWebDriverEventHandler getOnWillInteract()
Fires when interaction with the webpage is about to begin.
This marks the start of the interaction phase including document state checking, scrolling, and feature computation.
suspend (WebPage, WebDriver) -> Any?
-
getOnDidInteract
abstract WebPageWebDriverEventHandler getOnDidInteract()
Fires when all interactions with the webpage have completed.
This event is fired after:
Document state checking
Webpage scrolling
Feature computation
This event is fired before:
Stopping the browser tab
suspend (WebPage, WebDriver) -> Any?
-
getOnWillCheckDocumentState
abstract WebPageWebDriverEventHandler getOnWillCheckDocumentState()
Fires when the document state is about to be checked.
suspend (WebPage, WebDriver) -> Any?
-
getOnDocumentFullyLoaded
abstract WebPageWebDriverEventHandler getOnDocumentFullyLoaded()
Fires when the document is fully loaded.
The "fullyLoaded" state is determined by a custom algorithm executed within the browser, which differs from the standard
Document.readyState.This custom algorithm is more reliable for:
Dynamic/AJAX content
Single Page Applications (SPAs)
Lazy-loaded content
suspend (WebPage, WebDriver) -> Any?
-
getOnWillScroll
abstract WebPageWebDriverEventHandler getOnWillScroll()
Fires when page scrolling is about to begin.
suspend (WebPage, WebDriver) -> Any?
-
getOnDidScroll
abstract WebPageWebDriverEventHandler getOnDidScroll()
Fires when page scrolling has completed.
suspend (WebPage, WebDriver) -> Any?
-
getOnDocumentSteady
abstract WebPageWebDriverEventHandler getOnDocumentSteady()
Fires when the document is steady and ready for custom actions.
This is the recommended event for custom RPA actions because:
Document has finished loading
Initial scrolling is complete
Page content is stable
Sufficient time remains before tab closure
Custom actions include clicking buttons, filling forms, expanding sections, triggering AJAX loads, etc.
Fired after: onDocumentFullyLoaded, onWillScroll, onDidScroll Fired before: onWillComputeFeature, onFeatureComputed, onDidInteract, onWillStopTab, onTabStopped
suspend (WebPage, WebDriver) -> Any?onDocumentSteady.addLast { page: WebPage, driver: WebDriver -> // Click to load more content driver.click("button.show-more") driver.waitForSelector(".additional-content") // Fill a search form driver.fill("input[name='search']", "query") driver.click("button[type='submit']") }
-
getOnWillComputeFeature
abstract WebPageWebDriverEventHandler getOnWillComputeFeature()
Fires when webpage features are about to be computed.
suspend (WebPage, WebDriver) -> Any?
-
getOnFeatureComputed
abstract WebPageWebDriverEventHandler getOnFeatureComputed()
Fires when webpage features have been computed.
suspend (WebPage, WebDriver) -> Any?
-
getOnWillStopTab
abstract WebPageWebDriverEventHandler getOnWillStopTab()
Fires when the browser tab is about to be stopped.
This is the last chance to perform actions before the tab closes. Good for capturing final state (screenshots, cookies, etc.).
Fired after:
Document state checking
Webpage scrolling
Feature computation
Webpage interaction
suspend (WebPage, WebDriver) -> Any?onWillStopTab.addLast { page: WebPage, driver: WebDriver -> val screenshot = driver.screenshot() saveScreenshot(page.url, screenshot) }
-
getOnTabStopped
abstract WebPageWebDriverEventHandler getOnTabStopped()
Fires when the browser tab has been stopped.
This is the final browse event. The WebDriver may have limited functionality at this point.
suspend (WebPage, WebDriver) -> Any?
-
-
-
-