NavigationListener


public interface NavigationListener


Page identification and lifecycle APIs.

This class provides callbacks to identify the different stages of navigation. For more information about the navigation lifecycle, please see the Life of a Navigation Presentation.

Note: These navigation callbacks only fire for navigations happening on the main frame.

Navigation lifecycle events:

Summary

Nested types

Denotes that the onNavigationVisible callback is experimental.

Public methods

default void
onFirstContentfulPaintMillis(@NonNull Page page, long durationMillis)

This method is deprecated.

Use onFirstContentfulPaintMillis instead.

default void
onFirstContentfulPaintMillis(
    @NonNull PageState pageState,
    long durationMillis
)

Called when the page achieves "First Contentful Paint".

default void
onLargestContentfulPaintMillis(@NonNull Page page, long durationMillis)

This method is deprecated.

Use onLargestContentfulPaintMillis instead.

default void
onLargestContentfulPaintMillis(
    @NonNull PageState pageState,
    long durationMillis
)

Called when the page fires a "Largest Contentful Paint" event.

default void

This method is deprecated.

Use onNavigationCompleted instead.

default void

Called when a navigation completes.

default void

This method is deprecated.

Use onNavigationRedirected instead.

default void
onNavigationRedirected(
    @NonNull NavigationState navigationState,
    @NonNull NavigationRedirectParameters navigationRedirectParameters
)

Called when a navigation is redirected.

default void

This method is deprecated.

Use onNavigationStarted instead.

default void

Called when a navigation starts, including same-document navigations.

default void

Called when a navigation is made visible

default void

This method is deprecated.

Use onPageDeleted instead.

default void

Called when any Page is evicted/destroyed.

default void

This method is deprecated.

Use onPageDomContentLoadedEvent instead.

default void

Called when the DOMContentLoaded event is fired for the current page.

default void

This method is deprecated.

Use onPageLoadEvent instead.

default void

Called when the window.load event is fired for the current page.

default void
onPerformanceMarkMillis(
    @NonNull Page page,
    @NonNull String markName,
    long markTimeMillis
)

This method is deprecated.

Use onPerformanceMarkMillis instead.

default void
onPerformanceMarkMillis(
    @NonNull PageState pageState,
    @NonNull String markName,
    long markTimeMillis
)

Called when the page registers a performance mark.

Public methods

onFirstContentfulPaintMillis

Added in 1.16.0
Deprecated in 1.19.0-alpha01
default void onFirstContentfulPaintMillis(@NonNull Page page, long durationMillis)

Called when the page achieves "First Contentful Paint".

See First Contentful Paint (FCP) for a definition.

Note: Delivery of this event may be delayed due to batching with other events, so it may not be sent in real-time.

This method is called only if NAVIGATION_LISTENER is supported. You can check whether that flag is supported using isFeatureSupported.

Parameters
@NonNull Page page

The Page for which the First Contentful Paint occurred.

long durationMillis

Navigation to First Contentful Paint duration in milliseconds.

onFirstContentfulPaintMillis

default void onFirstContentfulPaintMillis(
    @NonNull PageState pageState,
    long durationMillis
)

Called when the page achieves "First Contentful Paint".

See First Contentful Paint (FCP) for a definition.

Note: Delivery of this event may be delayed due to batching with other events, so it may not be sent in real-time.

This method is called only if NAVIGATION_LISTENER is supported. You can check whether that flag is supported using isFeatureSupported.

Parameters
@NonNull PageState pageState

The Page's state at which the First Contentful Paint occurred.

long durationMillis

Navigation to First Contentful Paint duration in milliseconds.

onLargestContentfulPaintMillis

Added in 1.16.0
Deprecated in 1.19.0-alpha01
default void onLargestContentfulPaintMillis(@NonNull Page page, long durationMillis)

Called when the page fires a "Largest Contentful Paint" event.

See Largest Contentful Paint (LCP) for a definition.

Note: Delivery of this event may be delayed due to batching with other events, so it may not be sent in real-time.

This method is called only if NAVIGATION_LISTENER is supported. You can check whether that flag is supported using isFeatureSupported.

Parameters
@NonNull Page page

The Page for which the Largest Contentful Paint occurred.

long durationMillis

Navigation to Largest Contentful Paint duration in milliseconds.

onLargestContentfulPaintMillis

default void onLargestContentfulPaintMillis(
    @NonNull PageState pageState,
    long durationMillis
)

Called when the page fires a "Largest Contentful Paint" event.

See Largest Contentful Paint (LCP) for a definition.

Note: Delivery of this event may be delayed due to batching with other events, so it may not be sent in real-time.

This method is called only if NAVIGATION_LISTENER is supported. You can check whether that flag is supported using isFeatureSupported.

Parameters
@NonNull PageState pageState

The Page's state at which the Largest Contentful Paint occurred.

long durationMillis

Navigation to Largest Contentful Paint duration in milliseconds.

onNavigationCompleted

Added in 1.15.0
Deprecated in 1.19.0-alpha01
default void onNavigationCompleted(@NonNull Navigation navigation)

Called when a navigation completes.

The navigation might not have actually committed (e.g., results in 204/download/cancelled), but those that do they will have committed by this point.

Parameters
@NonNull Navigation navigation

The Navigation object representing the completed navigation.

onNavigationCompleted

default void onNavigationCompleted(@NonNull NavigationState navigationState)

Called when a navigation completes.

The navigation might not have actually committed (e.g., results in 204/download/cancelled), but those that do they will have committed by this point.

Parameters
@NonNull NavigationState navigationState

An immutable snapshot of the Navigation's state at the point the Navigation is completed.

onNavigationRedirected

Added in 1.15.0
Deprecated in 1.19.0-alpha01
default void onNavigationRedirected(@NonNull Navigation navigation)

Called when a navigation is redirected.

Parameters
@NonNull Navigation navigation

The Navigation object representing the redirected navigation.

onNavigationRedirected

default void onNavigationRedirected(
    @NonNull NavigationState navigationState,
    @NonNull NavigationRedirectParameters navigationRedirectParameters
)

Called when a navigation is redirected.

Parameters
@NonNull NavigationState navigationState

An immutable snapshot of the Navigation's state at the point the Navigation is redirected.

@NonNull NavigationRedirectParameters navigationRedirectParameters

An object which exposes response headers for the callback

onNavigationStarted

Added in 1.15.0
Deprecated in 1.19.0-alpha01
default void onNavigationStarted(@NonNull Navigation navigation)

Called when a navigation starts, including same-document navigations.

Note: These navigation callbacks only fire for navigations happening on the main frame.

Parameters
@NonNull Navigation navigation

The Navigation object representing the started navigation.

onNavigationStarted

default void onNavigationStarted(@NonNull NavigationState navigationState)

Called when a navigation starts, including same-document navigations.

Note: These navigation callbacks only fire for navigations happening on the main frame.

Note: Calling super will call the old onNavigationStarted

Parameters
@NonNull NavigationState navigationState

An immutable snapshot of the Navigation's state at the point when the Navigation is started.

onNavigationVisible

@NavigationListener.ExperimentalOnNavigationVisible
default void onNavigationVisible(@NonNull NavigationState navigationState)

Called when a navigation is made visible

Note: This method is only called if NAVIGATION_LISTENER_NAVIGATION_VISIBLE is supported.

Parameters
@NonNull NavigationState navigationState

An immutable snapshot of the Navigation's state at the point the Navigation is visible.

onPageDeleted

Added in 1.15.0
Deprecated in 1.19.0-alpha01
default void onPageDeleted(@NonNull Page page)

Called when any Page is evicted/destroyed. This can occur immediately on navigation, or later if the page is BFCached and subsequently evicted.

Parameters
@NonNull Page page

The Page that was evicted or destroyed.

onPageDeleted

default void onPageDeleted(@NonNull PageState pageState)

Called when any Page is evicted/destroyed. This can occur immediately on navigation, or later if the page is BFCached and subsequently evicted.

Parameters
@NonNull PageState pageState

An immutable snapshot of the Page's state at the point the Page is deleted.

onPageDomContentLoadedEvent

Added in 1.15.0
Deprecated in 1.19.0-alpha01
default void onPageDomContentLoadedEvent(@NonNull Page page)

Called when the DOMContentLoaded event is fired for the current page.

Parameters
@NonNull Page page

The Page for which the DOMContentLoaded event fired.

onPageDomContentLoadedEvent

default void onPageDomContentLoadedEvent(@NonNull PageState pageState)

Called when the DOMContentLoaded event is fired for the current page.

Parameters
@NonNull PageState pageState

An immutable snapshot of the Page's state at the point the DOMContentLoaded event is fired.

onPageLoadEvent

Added in 1.15.0
Deprecated in 1.19.0-alpha01
default void onPageLoadEvent(@NonNull Page page)

Called when the window.load event is fired for the current page.

Parameters
@NonNull Page page

The Page for which the window.load event fired.

onPageLoadEvent

default void onPageLoadEvent(@NonNull PageState pageState)

Called when the window.load event is fired for the current page.

Parameters
@NonNull PageState pageState

An immutable snapshot of the Page's state at the point the Page is loaded.

onPerformanceMarkMillis

Added in 1.16.0
Deprecated in 1.19.0-alpha01
default void onPerformanceMarkMillis(
    @NonNull Page page,
    @NonNull String markName,
    long markTimeMillis
)

Called when the page registers a performance mark.

See Performance: mark() method for a definition.

Note: Delivery of this event may be delayed due to batching with other events, so it may not be sent in real-time.

This method is called only if NAVIGATION_LISTENER is supported. You can check whether that flag is supported using isFeatureSupported.

Parameters
@NonNull Page page

The Page for which the performance mark was registered.

@NonNull String markName

The name of the performance mark.

long markTimeMillis

The time of the performance mark in milliseconds since Performance.timeOrigin.

onPerformanceMarkMillis

default void onPerformanceMarkMillis(
    @NonNull PageState pageState,
    @NonNull String markName,
    long markTimeMillis
)

Called when the page registers a performance mark.

See Performance: mark() method for a definition.

Note: Delivery of this event may be delayed due to batching with other events, so it may not be sent in real-time.

This method is called only if NAVIGATION_LISTENER is supported. You can check whether that flag is supported using isFeatureSupported.

Parameters
@NonNull PageState pageState

The Page's state at which the performance mark was registered.

@NonNull String markName

The name of the performance mark.

long markTimeMillis

The time of the performance mark in milliseconds since Performance.timeOrigin.