Interface BrowseEventHandlers

  • All Implemented Interfaces:

    
    public interface BrowseEventHandlers
    
                        

    Event 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 → onFetched
    • onDocumentSteady: 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")
        }
    }
    • Constructor Detail

    • 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?

      • 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?

      • 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?

      • 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']")
        }
      • 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?