androidx.webkit
The Jetpack Webkit library is a static library you can add to your Android application in order to use android.webkit APIs that are not available for older platform versions.
How to use this library in your app
Add this to your build.gradle file:
dependencies { implementation "androidx.webkit:webkit:1.14.0" }
Important: replace 1.14.0 with the latest version from https://developer.android.com/jetpack/androidx/releases/webkit.
Jetpack Webkit and Android System WebView
The Jetpack Webkit library enables developers to access new features that are available in the installed version of Android System WebView, even if those features are not exposed through the android.webkit framework API. It does this by dynamically checking the set of available features through the WebViewFeature class.
You should take care to always check feature availability before calling an API, as you otherwise risk a runtime crash if the WebView provider installed on a users device doesn't support the feature in question. This is most likely to happen if the user in question has not yet updated to a version of Android System WebView that supports the feature, but in rare cases WebView may also stop supporting a previously supported feature as part of an API deprecation.
Sample apps
Please check out the WebView samples on GitHub for a showcase of a handful of Jetpack Webkit APIs.
For more APIs, check out the sample app in the AndroidX repo.
Public bug tracker
If you find bugs in the Jetpack Webkit library or want to request new features, please file a ticket.
Migrating to Jetpack Webkit
For static methods:
Old code:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) { WebView.startSafeBrowsing(appContext, callback); }
New code:
if (WebViewFeature.isFeatureSupported(WebViewFeature.START_SAFE_BROWSING)) { WebViewCompat.startSafeBrowsing(appContext, callback); }
Or, if you are using a non-static method:
Old code:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { myWebView.postVisualStateCallback(requestId, callback); }
New code:
if (WebViewFeature.isFeatureSupported(WebViewFeature.VISUAL_STATE_CALLBACK)) { WebViewCompat.postVisualStateCallback(myWebView, requestId, callback); }
Experimental APIs
The Jetpack Webkit library contains a number of experimental APIs. These APIs will be marked with annotations that use the @RequiresOptIn annotation. We encourage you to try out these APIs in your application and file feedback on the public bug tracker if you encounter any issues with the API in the current shape.
When using an experimental API, you should keep the following points in mind:
- New features or changes may be introduced to experimental APIs. If you are using experimental APIs, we recommend that you always use the latest version of the library in your dependencies, and that you adopt changes in the API as soon as possible. For example, if you are building against the stable version of the library, you should make sure to upgrade to the next stable version as soon as it becomes available.
- Experimental APIs may be removed from future versions of the library. If this happens, you will not be able to continue using the API by relying on an older version of the library, since the support for the feature will also have been removed from new versions of WebView.
- The number of WebView versions that support a given experimental API depends on the release status of a given experimental API. For stable library releases, you can expect that WebView versions will continue to offer support until the next stable release of the library. For example, if an experimental API is available in
androidx.webkit:webkit:1.14.0, then the stable version of WebView will continue to support the API untilandroidx.webkit:webkit:1.15.0has been released, but after the next release the support may then be dropped in WebView versions, depending on the evolution of the API.
Interfaces
Navigation |
The Navigation instance passed by the navigation callbacks. |
NavigationListener |
Page identification and lifecycle APIs. |
OutcomeReceiverCompat |
Callback interface intended for use when an asynchronous operation may result in a failure. |
Page |
This class serves solely as a key for Page-associated data. |
PrerenderOperationCallback |
Callback interface for the prerender operation. |
Profile |
A Profile represents one browsing session for WebView. |
ProfileStore |
Manages any creation, deletion for |
ScriptHandler |
This interface represents the return result from |
StartUpLocation |
The code location where WebView startup was triggered. |
WebNavigationClient |
Page identification and lifecycle APIs. |
WebViewAssetLoader.PathHandler |
A handler that produces responses for a registered path. |
WebViewCompat.VisualStateCallback |
Callback interface supplied to |
WebViewCompat.WebMessageListener |
This listener receives messages sent on the JavaScript object which was injected by |
WebViewCompat.WebViewStartUpCallback |
Callback interface for |
WebViewStartUpResult |
Result object associated with |
Classes
BackForwardCacheSettings |
A class for developers to configure the back-forward cache on a |
BackForwardCacheSettings.Builder |
Builder for |
CookieManagerCompat |
Compatibility version of |
CustomHeader |
A HTTP header name-value pair that will be sent on all requests to origins that match the given origin rules. |
DropDataContentProvider |
WebView provides partial support for Android Drag and Drop allowing images, text and links to be dragged out of a WebView. |
JavaScriptReplyProxy |
This class represents the JavaScript object injected by |
NoVarySearchHeader |
The No-Vary-Search header specifies a set of rules that define how a URL's query parameters will affect cache matching. |
ProcessGlobalConfig |
Process Global Configuration for WebView. |
ProxyConfig |
Config for |
ProxyConfig.Builder |
ProxyConfig builder. |
ProxyConfig.ProxyRule |
Class that holds a scheme filter and a proxy URL. |
ProxyController |
Manages setting and clearing a process-specific override for the Android system-wide proxy settings that govern network requests made by |
RestrictionAllowlist |
RestrictionAllowlist can be used to scope WebView behaviors to particular origin patterns. |
RestrictionAllowlist.Builder |
RestrictionAllowlist builder. |
SafeBrowsingResponseCompat |
Compatibility version of |
ServiceWorkerClientCompat |
Base class for clients to capture Service Worker related callbacks, see |
ServiceWorkerControllerCompat |
Manages Service Workers used by WebView. |
ServiceWorkerWebSettingsCompat |
Manages settings state for all Service Workers. |
SpeculativeLoadingConfig |
Represents a configuration for speculative loading in a |
SpeculativeLoadingConfig.Builder |
|
SpeculativeLoadingParameters |
Parameters for customizing the prefetch. |
SpeculativeLoadingParameters.Builder |
A builder class to use to construct the |
TracingConfig |
Holds tracing configuration information and predefined settings for |
TracingConfig.Builder |
Builder used to create |
TracingController |
Manages tracing of WebViews. |
URLUtilCompat |
Compatibility versions of methods in |
UserAgentMetadata |
Holds user-agent metadata information and uses to generate user-agent client hints. |
UserAgentMetadata.BrandVersion |
Class that holds brand name, major version and full version. |
UserAgentMetadata.BrandVersion.Builder |
Builder used to create |
UserAgentMetadata.Builder |
Builder used to create |
WebMessageCompat |
The Java representation of the HTML5 PostMessage event. |
WebMessagePortCompat |
The Java representation of the HTML5 message ports. |
WebMessagePortCompat.WebMessageCallbackCompat |
The listener for handling MessagePort events. |
WebResourceErrorCompat |
Compatibility version of |
WebResourceRequestCompat |
Compatibility version of |
WebResourceResponseCompat |
Compatibility version of |
WebSettingsCompat |
Compatibility version of |
WebStorageCompat |
Compatibility class for |
WebViewAssetLoader |
Helper class to load local files including application's static assets and resources using http(s):// URLs inside a |
WebViewAssetLoader.AssetsPathHandler |
Handler class to open a file from assets directory in the application APK. |
WebViewAssetLoader.Builder |
A builder class for constructing |
WebViewAssetLoader.InternalStoragePathHandler |
Handler class to open files from application internal storage. |
WebViewAssetLoader.ResourcesPathHandler |
Handler class to open a file from resources directory in the application APK. |
WebViewBuilder |
WebViewBuilder can be used in place of |
WebViewClientCompat |
Compatibility version of |
WebViewCompat |
Compatibility version of |
WebViewFeature |
Utility class for checking which WebView Support Library features are supported on the device. |
WebViewMediaIntegrityApiStatusConfig |
Configuration to set API enablement status for site origins through override rules. |
WebViewMediaIntegrityApiStatusConfig.Builder |
Builds a |
WebViewRenderProcess |
WebViewRenderProcess provides an opaque handle to a WebView renderer. |
WebViewRenderProcessClient |
Used to receive callbacks on |
WebViewStartUpConfig |
Configuration object for |
WebViewStartUpConfig.Builder |
Exceptions
PrefetchException |
Super class for all asynchronous exceptions produced by |
PrefetchNetworkException |
Class for network &server related Exceptions produced by |
PrerenderException |
Super class for all asynchronous exceptions produced by |
WebViewBuilderException |
Thrown by |
Annotations
Profile.ExperimentalAddQuicHints |
Denotes that the Profile#addQuicHints API surface is experimental. |
Profile.ExperimentalOriginMatchedHeader |
Denotes that the OriginMatchedHeader API surface is experimental. |
Profile.ExperimentalPreconnect |
Denotes that the Profile#preconnect API surface is experimental. |
Profile.ExperimentalUrlPrefetch |
Denotes that the UrlPrefetch API surface is experimental. |
Profile.ExperimentalWarmUpRendererProcess |
Denotes that the WarmUpRendererProcess API surface is experimental. |
WebNavigationClient.ExperimentalNavigationCallback |
Denotes |
WebSettingsCompat.ExperimentalBackForwardCacheSettings |
Denotes that the SpeculativeLoading API surface is experimental. |
WebSettingsCompat.ExperimentalSpeculativeLoading |
Denotes that the SpeculativeLoading API surface is experimental. |
WebViewBuilder.Experimental |
|
WebViewCompat.ExperimentalAsyncStartUp |
Denotes that the async startup-related API (e.g |
WebViewCompat.ExperimentalSaveState |
Denotes that the WebViewCompat#saveState API surface is experimental. |