# NavigationState

Artifact: [androidx.webkit:webkit](https://developer.android.com/jetpack/androidx/releases/webkit) [View Source](https://cs.android.com/search?q=file:androidx/webkit/NavigationState.java+class:androidx.webkit.NavigationState) Added in [1.19.0-alpha01](https://developer.android.com/jetpack/androidx/releases/webkit#1.19.0-alpha01)

*** ** * ** ***


```
@AnyThread
public final class NavigationState
```

<br />

*** ** * ** ***

This class serves as an immutable snapshot of a `https://developer.android.com/reference/androidx/webkit/Navigation` instance at a certain point in time, captured every time a callback (e.g. `https://developer.android.com/reference/androidx/webkit/NavigationListener#onNavigationStarted(androidx.webkit.Navigation)`) is called.

Note: Do not use `https://developer.android.com/reference/androidx/webkit/NavigationState` as a key to connect callbacks, use `https://developer.android.com/reference/androidx/webkit/Navigation` instead from `https://developer.android.com/reference/androidx/webkit/NavigationState#getNavigation()`.

## Summary

| ### Public methods |
|---|---|
| `boolean` | `https://developer.android.com/reference/androidx/webkit/NavigationState#didCommit()()` Indicates whether the navigation committed (i.e., did not get aborted/return 204/etc). |
| `boolean` | `https://developer.android.com/reference/androidx/webkit/NavigationState#didCommitErrorPage()()` Indicates whether the navigation committed an error page. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/webkit/Navigation` | `https://developer.android.com/reference/androidx/webkit/NavigationState#getNavigation()()` Returns the navigation linked to this NavigationState snapshot |
| `long` | `@https://developer.android.com/reference/androidx/annotation/RequiresFeature(name = https://developer.android.com/reference/androidx/webkit/WebViewFeature.NAVIGATION_GET_NAVIGATION_START_UPTIME_MILLIS, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported") https://developer.android.com/reference/androidx/webkit/NavigationState#getNavigationStartUptimeMillis()()` Returns the timestamp when this navigation was initiated. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/androidx/webkit/PageState` | `https://developer.android.com/reference/androidx/webkit/NavigationState#getPageState()()` Returns the PageState that the navigation commits into. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/util/Map.html<https://developer.android.com/reference/java/lang/String.html, https://developer.android.com/reference/java/lang/String.html>` | `@https://developer.android.com/reference/androidx/annotation/RequiresFeature(name = https://developer.android.com/reference/androidx/webkit/WebViewFeature.NAVIGATION_GET_RESPONSE_HEADERS, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported") https://developer.android.com/reference/androidx/webkit/NavigationState#getResponseHeaders()()` Returns the HTTP response headers received for this navigation. |
| `int` | `https://developer.android.com/reference/androidx/webkit/NavigationState#getStatusCode()()` Returns the status code received by the navigation. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/webkit/NavigationState#getUrl()()` Returns the URL of the Navigation's state at a point in time |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/androidx/webkit/WebResourceErrorCompat` | `@https://developer.android.com/reference/androidx/annotation/RequiresFeature(name = https://developer.android.com/reference/androidx/webkit/WebViewFeature.NAVIGATION_GET_WEB_RESOURCE_ERROR, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported") https://developer.android.com/reference/androidx/webkit/NavigationState#getWebResourceError()()` Navigation error information for the navigation load. |
| `boolean` | `https://developer.android.com/reference/androidx/webkit/NavigationState#isBack()()` Indicates whether the navigation is a history back navigation. |
| `boolean` | `https://developer.android.com/reference/androidx/webkit/NavigationState#isForward()()` Indicates whether the navigation is a history forward navigation. |
| `boolean` | `https://developer.android.com/reference/androidx/webkit/NavigationState#isHistory()()` Indicates whether the navigation is a history navigation. |
| `boolean` | `https://developer.android.com/reference/androidx/webkit/NavigationState#isReload()()` Indicates whether the navigation is a reload navigation. |
| `boolean` | `https://developer.android.com/reference/androidx/webkit/NavigationState#isRestore()()` Indicates whether the navigation is a restore navigation after calling `https://developer.android.com/reference/android/webkit/WebView.html#restoreState(android.os.Bundle)`. |
| `boolean` | `https://developer.android.com/reference/androidx/webkit/NavigationState#isSameDocument()()` Indicates whether the navigation is a same-document navigation. |
| `boolean` | `https://developer.android.com/reference/androidx/webkit/NavigationState#wasInitiatedByPage()()` Indicates whether the navigation is initiated by the page/renderer (e.g., link clicks, JS script) instead of the browser/app (e.g., loadUrl calls). |

## Public methods

### didCommit

Added in [1.19.0-alpha01](https://developer.android.com/jetpack/androidx/releases/webkit#1.19.0-alpha01)

```
public boolean didCommit()
```

Indicates whether the navigation committed (i.e., did not get aborted/return 204/etc).

Note: This will return true if `https://developer.android.com/reference/androidx/webkit/NavigationState#didCommitErrorPage()` returns true.

| Returns |
|---|---|
| `boolean` | True if committed, false otherwise. |

### didCommitErrorPage

Added in [1.19.0-alpha01](https://developer.android.com/jetpack/androidx/releases/webkit#1.19.0-alpha01)

```
public boolean didCommitErrorPage()
```

Indicates whether the navigation committed an error page.

| Returns |
|---|---|
| `boolean` | True if an error page was committed, false otherwise. |

### getNavigation

Added in [1.19.0-alpha01](https://developer.android.com/jetpack/androidx/releases/webkit#1.19.0-alpha01)

```
public @NonNull Navigation getNavigation()
```

Returns the navigation linked to this NavigationState snapshot

### getNavigationStartUptimeMillis

Added in [1.19.0-alpha01](https://developer.android.com/jetpack/androidx/releases/webkit#1.19.0-alpha01)

```
@RequiresFeature(name = WebViewFeature.NAVIGATION_GET_NAVIGATION_START_UPTIME_MILLIS, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
public long getNavigationStartUptimeMillis()
```

Returns the timestamp when this navigation was initiated.

The returned timestamp represents the time elapsed since device boot in milliseconds, excluding time spent in deep sleep. This timebase is equivalent to `https://developer.android.com/reference/android/os/SystemClock.html#uptimeMillis()`.

| Returns |
|---|---|
| `long` | The start time of the navigation in uptime milliseconds. |

### getPageState

Added in [1.19.0-alpha01](https://developer.android.com/jetpack/androidx/releases/webkit#1.19.0-alpha01)

```
public @Nullable PageState getPageState()
```

Returns the PageState that the navigation commits into.

Note: This method will return `null` if the navigation had not committed a page when this snapshot was taken, or never commits one (204/download). If the navigation successfully commits a page, this method will return the corresponding `https://developer.android.com/reference/androidx/webkit/PageState` object for the page. This could wrap a newly created `https://developer.android.com/reference/androidx/webkit/Page` or a previously seen `https://developer.android.com/reference/androidx/webkit/Page` in the case of BFCache (Back/Forward Cache).

Note: Once this method returns a non-null `https://developer.android.com/reference/androidx/webkit/PageState` object for a specific navigation's `https://developer.android.com/reference/androidx/webkit/Page`, `https://developer.android.com/reference/androidx/webkit/PageState#getPage()` will always return the same `https://developer.android.com/reference/androidx/webkit/Page` object for that navigation.

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/androidx/webkit/PageState` | The `https://developer.android.com/reference/androidx/webkit/PageState` object, or `null` if the navigation had not committed a Page when the snapshot was taken. (e.g., [204](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/204)/download). |

### getResponseHeaders

Added in [1.19.0-alpha01](https://developer.android.com/jetpack/androidx/releases/webkit#1.19.0-alpha01)

```
@RequiresFeature(name = WebViewFeature.NAVIGATION_GET_RESPONSE_HEADERS, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
public @Nullable Map<String, String> getResponseHeaders()
```

Returns the HTTP response headers received for this navigation.

The response headers are not available until the navigation has completed, so this method will return `null` until `https://developer.android.com/reference/androidx/webkit/NavigationListener#onNavigationCompleted(androidx.webkit.NavigationState)` has been called for this navigation.

The returned map will be empty if the navigation did not receive an HTTP response, for example for same-document navigations, navigations to non-HTTP URLs (such as `file://` or `about:blank`) or navigations that failed before a response was received.

The `Set-Cookie` header is never included. Only the headers of the final response are returned, the headers of any redirects are exposed via `https://developer.android.com/reference/androidx/webkit/NavigationRedirectParameters#getResponseHeaders()` in `https://developer.android.com/reference/androidx/webkit/NavigationListener#onNavigationRedirected(androidx.webkit.NavigationState,androidx.webkit.NavigationRedirectParameters)`

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/util/Map.html<https://developer.android.com/reference/java/lang/String.html, https://developer.android.com/reference/java/lang/String.html>` | An unmodifiable `https://developer.android.com/reference/java/util/Map.html` from header name to header value, or `null` if the navigation has not completed yet. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/UnsupportedOperationException.html` | if the `https://developer.android.com/reference/androidx/webkit/WebViewFeature#NAVIGATION_GET_RESPONSE_HEADERS()` feature is not supported. This should be checked before use with `https://developer.android.com/reference/androidx/webkit/WebViewFeature#isFeatureSupported(java.lang.String)`. |

### getStatusCode

Added in [1.19.0-alpha01](https://developer.android.com/jetpack/androidx/releases/webkit#1.19.0-alpha01)

```
public int getStatusCode()
```

Returns the status code received by the navigation.

| Returns |
|---|---|
| `int` | The HTTP status code. |

### getUrl

Added in [1.19.0-alpha01](https://developer.android.com/jetpack/androidx/releases/webkit#1.19.0-alpha01)

```
public @NonNull String getUrl()
```

Returns the URL of the Navigation's state at a point in time

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html` | The URL of this NavigationState as a String. |

### getWebResourceError

Added in [1.19.0-alpha01](https://developer.android.com/jetpack/androidx/releases/webkit#1.19.0-alpha01)

```
@RequiresFeature(name = WebViewFeature.NAVIGATION_GET_WEB_RESOURCE_ERROR, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
public @Nullable WebResourceErrorCompat getWebResourceError()
```

Navigation error information for the navigation load.

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/androidx/webkit/WebResourceErrorCompat` | The `https://developer.android.com/reference/androidx/webkit/WebResourceErrorCompat` object, or `null` if there is no error for this navigation. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/UnsupportedOperationException.html` | if the `https://developer.android.com/reference/androidx/webkit/WebViewFeature#NAVIGATION_GET_WEB_RESOURCE_ERROR()` feature is not supported. This should be checked before use with `https://developer.android.com/reference/androidx/webkit/WebViewFeature#isFeatureSupported(java.lang.String)`. |

### isBack

Added in [1.19.0-alpha01](https://developer.android.com/jetpack/androidx/releases/webkit#1.19.0-alpha01)

```
public boolean isBack()
```

Indicates whether the navigation is a history back navigation.

| Returns |
|---|---|
| `boolean` | True if back navigation, false otherwise. |

### isForward

Added in [1.19.0-alpha01](https://developer.android.com/jetpack/androidx/releases/webkit#1.19.0-alpha01)

```
public boolean isForward()
```

Indicates whether the navigation is a history forward navigation.

| Returns |
|---|---|
| `boolean` | True if forward navigation, false otherwise. |

### isHistory

Added in [1.19.0-alpha01](https://developer.android.com/jetpack/androidx/releases/webkit#1.19.0-alpha01)

```
public boolean isHistory()
```

Indicates whether the navigation is a history navigation.

| Returns |
|---|---|
| `boolean` | True if history, false otherwise. |

### isReload

Added in [1.19.0-alpha01](https://developer.android.com/jetpack/androidx/releases/webkit#1.19.0-alpha01)

```
public boolean isReload()
```

Indicates whether the navigation is a reload navigation.

| Returns |
|---|---|
| `boolean` | True if reload, false otherwise. |

### isRestore

Added in [1.19.0-alpha01](https://developer.android.com/jetpack/androidx/releases/webkit#1.19.0-alpha01)

```
public boolean isRestore()
```

Indicates whether the navigation is a restore navigation after calling `https://developer.android.com/reference/android/webkit/WebView.html#restoreState(android.os.Bundle)`.

| Returns |
|---|---|
| `boolean` | True if session restore, false otherwise. |

### isSameDocument

Added in [1.19.0-alpha01](https://developer.android.com/jetpack/androidx/releases/webkit#1.19.0-alpha01)

```
public boolean isSameDocument()
```

Indicates whether the navigation is a same-document navigation.

| Returns |
|---|---|
| `boolean` | True if same-document, false otherwise. |

### wasInitiatedByPage

Added in [1.19.0-alpha01](https://developer.android.com/jetpack/androidx/releases/webkit#1.19.0-alpha01)

```
public boolean wasInitiatedByPage()
```

Indicates whether the navigation is initiated by the page/renderer (e.g., link clicks, JS script) instead of the browser/app (e.g., loadUrl calls).

| Returns |
|---|---|
| `boolean` | True if page-initiated, false otherwise. |