ServiceWorkerWebSettingsCompat
@AnyThread
abstract class ServiceWorkerWebSettingsCompat
Manages settings state for all Service Workers. These settings are not tied to the lifetime of any WebView because service workers can outlive WebView instances. The settings are similar to WebSettings but only settings relevant to Service Workers are supported.
Summary
Public functions |
|
|---|---|
abstract Boolean |
@RequiresFeature(name = WebViewFeature.SERVICE_WORKER_CONTENT_ACCESS, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")Gets whether Service Workers support content URL access. |
abstract Boolean |
@RequiresFeature(name = WebViewFeature.SERVICE_WORKER_FILE_ACCESS, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")Gets whether Service Workers support file access. |
abstract Boolean |
@RequiresFeature(name = WebViewFeature.SERVICE_WORKER_BLOCK_NETWORK_LOADS, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")Gets whether Service Workers are prohibited from loading any resources from the network. |
abstract Int |
@RequiresFeature(name = WebViewFeature.SERVICE_WORKER_CACHE_MODE, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")Gets the current setting for overriding the cache mode. |
abstract (Mutable)Set<String!> |
@RequiresFeature(name = WebViewFeature.REQUESTED_WITH_HEADER_ALLOW_LIST, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")This function is deprecated. The origin trial to disable the X-Requested-With feature has ended, so this API now just returns an empty set. |
abstract Boolean |
@RequiresFeature(name = WebViewFeature.COOKIE_INTERCEPT, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")Returns whether cookie access during request intercept is enabled. |
abstract Unit |
@RequiresFeature(name = WebViewFeature.SERVICE_WORKER_CONTENT_ACCESS, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")Enables or disables content URL access from Service Workers. |
abstract Unit |
@RequiresFeature(name = WebViewFeature.SERVICE_WORKER_FILE_ACCESS, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")Enables or disables file access within Service Workers. |
abstract Unit |
@RequiresFeature(name = WebViewFeature.SERVICE_WORKER_BLOCK_NETWORK_LOADS, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")Sets whether Service Workers should not load resources from the network. |
abstract Unit |
@RequiresFeature(name = WebViewFeature.SERVICE_WORKER_CACHE_MODE, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")Overrides the way the cache is used. |
abstract Unit |
@RequiresFeature(name = WebViewFeature.COOKIE_INTERCEPT, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")This method controls if the relevant |
abstract Unit |
@RequiresFeature(name = WebViewFeature.REQUESTED_WITH_HEADER_ALLOW_LIST, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")This function is deprecated. The origin trial to disable the X-Requested-With feature has ended, so this API no longer does anything. |
Public functions
getAllowContentAccess
@RequiresFeature(name = WebViewFeature.SERVICE_WORKER_CONTENT_ACCESS, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
abstract fun getAllowContentAccess(): Boolean
Gets whether Service Workers support content URL access.
This method should only be called if isFeatureSupported returns true for SERVICE_WORKER_CONTENT_ACCESS.
| See also | |
|---|---|
setAllowContentAccess |
getAllowFileAccess
@RequiresFeature(name = WebViewFeature.SERVICE_WORKER_FILE_ACCESS, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
abstract fun getAllowFileAccess(): Boolean
Gets whether Service Workers support file access.
This method should only be called if isFeatureSupported returns true for SERVICE_WORKER_FILE_ACCESS.
| See also | |
|---|---|
setAllowFileAccess |
getBlockNetworkLoads
@RequiresFeature(name = WebViewFeature.SERVICE_WORKER_BLOCK_NETWORK_LOADS, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
abstract fun getBlockNetworkLoads(): Boolean
Gets whether Service Workers are prohibited from loading any resources from the network.
This method should only be called if isFeatureSupported returns true for SERVICE_WORKER_BLOCK_NETWORK_LOADS.
| Returns | |
|---|---|
Boolean |
|
| See also | |
|---|---|
setBlockNetworkLoads |
getCacheMode
@RequiresFeature(name = WebViewFeature.SERVICE_WORKER_CACHE_MODE, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
abstract fun getCacheMode(): Int
Gets the current setting for overriding the cache mode.
This method should only be called if isFeatureSupported returns true for SERVICE_WORKER_CACHE_MODE.
| Returns | |
|---|---|
Int |
the current setting for overriding the cache mode |
| See also | |
|---|---|
setCacheMode |
@RequiresFeature(name = WebViewFeature.REQUESTED_WITH_HEADER_ALLOW_LIST, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
abstract fungetRequestedWithHeaderOriginAllowList(): (Mutable)Set<String!>
Get the currently configured allow-list of origins, which is guaranteed to receive the X-Requested-With HTTP header on requests from service workers.
Any origin not on this allow-list may not receive the header, depending on the current installed WebView provider.
The format of the strings in the allow-list follows the origin rules of addWebMessageListener.
isIncludeCookiesOnShouldInterceptRequestEnabled
@RequiresFeature(name = WebViewFeature.COOKIE_INTERCEPT, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
abstract fun isIncludeCookiesOnShouldInterceptRequestEnabled(): Boolean
Returns whether cookie access during request intercept is enabled.
This method should only be called if isFeatureSupported returns true for COOKIE_INTERCEPT.
setAllowContentAccess
@RequiresFeature(name = WebViewFeature.SERVICE_WORKER_CONTENT_ACCESS, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
abstract fun setAllowContentAccess(allow: Boolean): Unit
Enables or disables content URL access from Service Workers.
This method should only be called if isFeatureSupported returns true for SERVICE_WORKER_CONTENT_ACCESS.
setAllowFileAccess
@RequiresFeature(name = WebViewFeature.SERVICE_WORKER_FILE_ACCESS, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
abstract fun setAllowFileAccess(allow: Boolean): Unit
Enables or disables file access within Service Workers.
This method should only be called if isFeatureSupported returns true for SERVICE_WORKER_FILE_ACCESS.
| See also | |
|---|---|
setAllowFileAccess |
|
getAllowContentAccess |
setBlockNetworkLoads
@RequiresFeature(name = WebViewFeature.SERVICE_WORKER_BLOCK_NETWORK_LOADS, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
abstract fun setBlockNetworkLoads(flag: Boolean): Unit
Sets whether Service Workers should not load resources from the network.
This method should only be called if isFeatureSupported returns true for SERVICE_WORKER_BLOCK_NETWORK_LOADS.
| Parameters | |
|---|---|
flag: Boolean |
|
| See also | |
|---|---|
setBlockNetworkLoads |
|
getBlockNetworkLoads |
setCacheMode
@RequiresFeature(name = WebViewFeature.SERVICE_WORKER_CACHE_MODE, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
abstract fun setCacheMode(mode: Int): Unit
Overrides the way the cache is used.
This method should only be called if isFeatureSupported returns true for SERVICE_WORKER_CACHE_MODE.
| Parameters | |
|---|---|
mode: Int |
the mode to use. One of |
| See also | |
|---|---|
setCacheMode |
|
getCacheMode |
setIncludeCookiesOnShouldInterceptRequestEnabled
@RequiresFeature(name = WebViewFeature.COOKIE_INTERCEPT, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
abstract fun setIncludeCookiesOnShouldInterceptRequestEnabled(enabled: Boolean): Unit
This method controls if the relevant Cookie header will be added to the WebResourceRequest object passed to shouldInterceptRequest. It also enables the use of setCookies, which will otherwise be ignored.
Prefer using this method over calling CookieManager as part of intercepting requests if it is necessary to access cookies, as this approach will provide the correct set of cookies for the request.
This method should only be called if isFeatureSupported returns true for COOKIE_INTERCEPT.
| Parameters | |
|---|---|
enabled: Boolean |
Whether cookie access during request intercept should be enabled. |
@RequiresFeature(name = WebViewFeature.REQUESTED_WITH_HEADER_ALLOW_LIST, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
abstract funsetRequestedWithHeaderOriginAllowList(allowList: (Mutable)Set<String!>): Unit
Set an allow-list of origins to receive the X-Requested-With HTTP header from service workers.
Historically, this header was sent on all requests from WebView, containing the app package name of the embedding app. Depending on the version of installed WebView, this may no longer be the case, as the header was deprecated in late 2022, and its use discontinued.
Apps can use this method to restore the legacy behavior for servers that still rely on the deprecated header, but it should not be used to identify the WebView to first-party servers under the control of the app developer.
The format of the strings in the allow-list follows the origin rules of addWebMessageListener.
| Throws | |
|---|---|
java.lang.IllegalArgumentException |
if the allow-list contains a malformed origin. |