belongs to Maven artifact androidx.webkit:webkit:1.0.0-alpha1

ServiceWorkerControllerCompat

public abstract class ServiceWorkerControllerCompat
extends Object

java.lang.Object
   ↳ 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

static ServiceWorkerControllerCompat getInstance()

Returns the default ServiceWorkerController instance.

abstract ServiceWorkerWebSettingsCompat getServiceWorkerWebSettings()

Gets the settings for all service workers.

abstract void setServiceWorkerClient(ServiceWorkerClientCompat client)

Sets the client to capture service worker related callbacks.

Inherited methods

Public methods

getInstance

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
ServiceWorkerControllerCompat the default ServiceWorkerController instance

getServiceWorkerWebSettings

ServiceWorkerWebSettingsCompat getServiceWorkerWebSettings ()

Gets the settings for all service workers.

Returns
ServiceWorkerWebSettingsCompat the current ServiceWorkerWebSettingsCompat

setServiceWorkerClient

void setServiceWorkerClient (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.

Parameters
client ServiceWorkerClientCompat