ServiceWorkerControllerCompat


@AnyThread
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 functions

java-static ServiceWorkerControllerCompat
@RequiresFeature(name = WebViewFeature.SERVICE_WORKER_BASIC_USAGE, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
getInstance()

Returns the default ServiceWorkerController instance.

abstract ServiceWorkerWebSettingsCompat

Gets the settings for all service workers.

abstract Unit

Sets the client to capture service worker related callbacks.

Public functions

getInstance

Added in 1.1.0
@RequiresFeature(name = WebViewFeature.SERVICE_WORKER_BASIC_USAGE, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
java-static fun getInstance(): ServiceWorkerControllerCompat

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.

This method should only be called if isFeatureSupported returns true for SERVICE_WORKER_BASIC_USAGE.

Returns
ServiceWorkerControllerCompat

the default ServiceWorkerController instance

getServiceWorkerWebSettings

Added in 1.1.0
abstract fun getServiceWorkerWebSettings(): ServiceWorkerWebSettingsCompat

Gets the settings for all service workers.

setServiceWorkerClient

Added in 1.1.0
abstract fun setServiceWorkerClient(client: ServiceWorkerClientCompat?): Unit

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.