ServiceWorkerControllerCompat
@AnyThread
public abstract class ServiceWorkerControllerCompat
Manages Service Workers used by WebView.
Example usage:
ServiceWorkerControllerCompat swController = ServiceWorkerControllerCompat.getInstance(); swController.setServiceWorkerClient(new ServiceWorkerClientCompat() { @Override public WebResourceResponse shouldInterceptRequest(WebResourceRequest request) { // Capture request here and generate response or allow pass-through // by returning null. return null; } });
Summary
Public methods |
|
|---|---|
static @NonNull ServiceWorkerControllerCompat |
@RequiresFeature(name = WebViewFeature.SERVICE_WORKER_BASIC_USAGE, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")Returns the default ServiceWorkerController instance. |
abstract @NonNull ServiceWorkerWebSettingsCompat |
Gets the settings for all service workers. |
abstract void |
Sets the client to capture service worker related callbacks. |
Public methods
getInstance
@RequiresFeature(name = WebViewFeature.SERVICE_WORKER_BASIC_USAGE, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
public static @NonNull ServiceWorkerControllerCompat getInstance()
Returns the default ServiceWorkerController instance. At present there is only one ServiceWorkerController instance for all WebView instances, however this restriction may be relaxed in the future.
| Returns | |
|---|---|
@NonNull ServiceWorkerControllerCompat |
the default ServiceWorkerController instance |
| Throws | |
|---|---|
java.lang.UnsupportedOperationException |
if the |
getServiceWorkerWebSettings
public abstract @NonNull ServiceWorkerWebSettingsCompat getServiceWorkerWebSettings()
Gets the settings for all service workers.
| Returns | |
|---|---|
@NonNull ServiceWorkerWebSettingsCompat |
the current |
setServiceWorkerClient
public abstract void setServiceWorkerClient(@Nullable ServiceWorkerClientCompat client)
Sets the client to capture service worker related callbacks.
A ServiceWorkerClientCompat should be set before any service workers are active, e.g. a safe place is before any WebView instances are created or pages loaded.