# Navigation

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

*** ** * ** ***


```
public final class Navigation
```

<br />

*** ** * ** ***

The Navigation instance passed by `https://developer.android.com/reference/androidx/webkit/NavigationListener`.

The same object will be used by the relevant callbacks for the same navigation, allowing the instance itself to be used as a key/ID to connect the callbacks for the same navigation through `https://developer.android.com/reference/java/lang/Object.html#equals(java.lang.Object)` and `https://developer.android.com/reference/java/lang/Object.html#hashCode()`.

The return values of `https://developer.android.com/reference/androidx/webkit/Navigation#wasInitiatedByPage()`, `https://developer.android.com/reference/androidx/webkit/Navigation#isReload()`, `https://developer.android.com/reference/androidx/webkit/Navigation#isHistory()`, `https://developer.android.com/reference/androidx/webkit/Navigation#isBack()`, `https://developer.android.com/reference/androidx/webkit/Navigation#isForward()` and `https://developer.android.com/reference/androidx/webkit/Navigation#isRestore()` are constant for a given Navigation. For the other methods:

- `https://developer.android.com/reference/androidx/webkit/Navigation#getPage()`, `https://developer.android.com/reference/androidx/webkit/Navigation#didCommit()` and `https://developer.android.com/reference/androidx/webkit/Navigation#didCommitErrorPage()` will only change when `https://developer.android.com/reference/androidx/webkit/NavigationListener#onNavigationCompleted(androidx.webkit.Navigation)` is called.
- `https://developer.android.com/reference/androidx/webkit/Navigation#getUrl()` will only change when `https://developer.android.com/reference/androidx/webkit/NavigationListener#onNavigationRedirected(androidx.webkit.Navigation)` is called.

## Summary

| ### Public methods |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/webkit/NavigationState` | `@https://developer.android.com/reference/androidx/annotation/AnyThread @https://developer.android.com/reference/androidx/annotation/RequiresFeature(name = https://developer.android.com/reference/androidx/webkit/WebViewFeature.NAVIGATION_LISTENER_NAVIGATION_STATE, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported") https://developer.android.com/reference/androidx/webkit/Navigation#captureState()()` Takes a snapshot of the navigation's state. |
| `boolean` | `https://developer.android.com/reference/androidx/webkit/Navigation#didCommit()()` Indicates whether the navigation committed (i.e., did not get aborted/return 204/etc). |
| `boolean` | `https://developer.android.com/reference/androidx/webkit/Navigation#didCommitErrorPage()()` Indicates whether the navigation committed an error page. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/androidx/webkit/Page` | `https://developer.android.com/reference/androidx/webkit/Navigation#getPage()()` Returns the Page that the navigation commits into. |
| `int` | `https://developer.android.com/reference/androidx/webkit/Navigation#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/Navigation#getUrl()()` Returns the URL of this navigation. |
| `@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/Navigation#getWebResourceError()()` Navigation error information for the navigation load. |
| `boolean` | `https://developer.android.com/reference/androidx/webkit/Navigation#isBack()()` Indicates whether the navigation is a history back navigation. |
| `boolean` | `https://developer.android.com/reference/androidx/webkit/Navigation#isForward()()` Indicates whether the navigation is a history forward navigation. |
| `boolean` | `https://developer.android.com/reference/androidx/webkit/Navigation#isHistory()()` Indicates whether the navigation is a history navigation. |
| `boolean` | `https://developer.android.com/reference/androidx/webkit/Navigation#isReload()()` Indicates whether the navigation is a reload navigation. |
| `boolean` | `https://developer.android.com/reference/androidx/webkit/Navigation#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/Navigation#isSameDocument()()` Indicates whether the navigation is a same-document navigation. |
| `boolean` | `https://developer.android.com/reference/androidx/webkit/Navigation#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

### captureState

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

```
@AnyThread
@RequiresFeature(name = WebViewFeature.NAVIGATION_LISTENER_NAVIGATION_STATE, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
public @NonNull NavigationState captureState()
```

Takes a snapshot of the navigation's state. This allows you to hold a consistent representation of the navigation at a certain point in time, as the Navigation object gets updated as the navigation progresses.

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/webkit/NavigationState` | The immutable `https://developer.android.com/reference/androidx/webkit/NavigationState` object. |

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

### didCommit

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

```
public boolean didCommit()
```

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

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

### didCommitErrorPage

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

```
public boolean didCommitErrorPage()
```

Indicates whether the navigation committed an error page.

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

### getPage

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

```
public @Nullable Page getPage()
```

Returns the Page that the navigation commits into.

Note: This method will initially return `null` when navigation begins. If the navigation successfully commits a page, this method will return the corresponding `https://developer.android.com/reference/androidx/webkit/Page` object. This could be 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/Page` object for a specific navigation, it 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/Page` | The `https://developer.android.com/reference/androidx/webkit/Page` object, or `null` if the navigation does not commit or result in a Page (e.g., [204](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/204)/download). |

### getStatusCode

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

```
public int getStatusCode()
```

Returns the status code received by the navigation.

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

### getUrl

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

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

Returns the URL of this navigation.

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

### getWebResourceError

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

```
@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.14.0](https://developer.android.com/jetpack/androidx/releases/webkit#1.14.0)

```
public boolean isBack()
```

Indicates whether the navigation is a history back navigation.

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

### isForward

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

```
public boolean isForward()
```

Indicates whether the navigation is a history forward navigation.

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

### isHistory

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

```
public boolean isHistory()
```

Indicates whether the navigation is a history navigation.

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

### isReload

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

```
public boolean isReload()
```

Indicates whether the navigation is a reload navigation.

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

### isRestore

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

```
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.14.0](https://developer.android.com/jetpack/androidx/releases/webkit#1.14.0)

```
public boolean isSameDocument()
```

Indicates whether the navigation is a same-document navigation.

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

### wasInitiatedByPage

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

```
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. |