Register now for Android Dev Summit 2019!

ServiceWorkerControllerCompat

abstract class ServiceWorkerControllerCompat
kotlin.Any
   ↳ androidx.webkit.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

open static ServiceWorkerControllerCompat

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 methods

getInstance

@NonNull open 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 WebViewFeature#isFeatureSupported(String) returns true for WebViewFeature#SERVICE_WORKER_BASIC_USAGE.

Return
ServiceWorkerControllerCompat: the default ServiceWorkerController instance

getServiceWorkerWebSettings

@NonNull abstract fun getServiceWorkerWebSettings(): ServiceWorkerWebSettingsCompat

Gets the settings for all service workers.

Return
ServiceWorkerWebSettingsCompat: the current ServiceWorkerWebSettingsCompat

setServiceWorkerClient

abstract fun setServiceWorkerClient(@Nullable 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.