Save the date! Android Dev Summit is coming to Mountain View, CA on November 7-8, 2018.
added in version 1.0.0
belongs to Maven artifact androidx.webkit:webkit:1.1.0-alpha01

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

added in version 1.0.0
public static 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.

This method should only be called if WebViewFeature.isFeatureSupported(String) returns true for WebViewFeature.SERVICE_WORKER_BASIC_USAGE.

Returns
ServiceWorkerControllerCompat the default ServiceWorkerController instance

getServiceWorkerWebSettings

added in version 1.0.0
public abstract ServiceWorkerWebSettingsCompat getServiceWorkerWebSettings ()

Gets the settings for all service workers.

Returns
ServiceWorkerWebSettingsCompat the current ServiceWorkerWebSettingsCompat

setServiceWorkerClient

added in version 1.0.0
public abstract 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