# ServiceWorkerClientCompat

# ServiceWorkerClientCompat

Artifact:[androidx.webkit:webkit](https://developer.android.com/jetpack/androidx/releases/webkit)  
[View Source](https://cs.android.com/search?q=file:androidx/webkit/ServiceWorkerClientCompat.java+class:androidx.webkit.ServiceWorkerClientCompat)  
Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/webkit#1.1.0)

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/androidx/webkit/ServiceWorkerClientCompat "View this page in Java")

<br />

```
abstract class ServiceWorkerClientCompat
```

<br />

*** ** * ** ***

Base class for clients to capture Service Worker related callbacks, see[ServiceWorkerControllerCompat](https://developer.android.com/reference/kotlin/androidx/webkit/ServiceWorkerControllerCompat)for usage example.

## Summary

|                                                                ### Public constructors                                                                |
|-------------------------------------------------------------------------------------------------------------------------------------------------------|
| [ServiceWorkerClientCompat](https://developer.android.com/reference/kotlin/androidx/webkit/ServiceWorkerClientCompat#ServiceWorkerClientCompat())`()` |

|                                                 ### Public functions                                                 |
|----------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `abstract `[WebResourceResponse](https://developer.android.com/reference/android/webkit/WebResourceResponse.html)`?` | `@`[WorkerThread](https://developer.android.com/reference/kotlin/androidx/annotation/WorkerThread) [shouldInterceptRequest](https://developer.android.com/reference/kotlin/androidx/webkit/ServiceWorkerClientCompat#shouldInterceptRequest(android.webkit.WebResourceRequest))`(request: `[WebResourceRequest](https://developer.android.com/reference/android/webkit/WebResourceRequest.html)`)` Notify the host application of a resource request and allow the application to return the data. |

## Public constructors

### ServiceWorkerClientCompat

Added in 1.1.0  

```
ServiceWorkerClientCompat()
```  

## Public functions

### shouldInterceptRequest

Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/webkit#1.1.0)  

```
@WorkerThread
abstract fun shouldInterceptRequest(request: WebResourceRequest): WebResourceResponse?
```

Notify the host application of a resource request and allow the application to return the data. If the return value is`null`, the Service Worker will continue to load the resource as usual. Otherwise, the return response and data will be used.

**Note:**This method is called on a thread other than the UI thread so clients should exercise caution when accessing private data or the view system.

This method is called only if[SERVICE_WORKER_SHOULD_INTERCEPT_REQUEST](https://developer.android.com/reference/kotlin/androidx/webkit/WebViewFeature#SERVICE_WORKER_SHOULD_INTERCEPT_REQUEST())is supported. You can check whether that flag is supported using[isFeatureSupported](https://developer.android.com/reference/kotlin/androidx/webkit/WebViewFeature#isFeatureSupported(java.lang.String)).  

|                                                   Parameters                                                    |
|-----------------------------------------------------------------------------------------------------------------|-----------------------------------------------|
| `request: `[WebResourceRequest](https://developer.android.com/reference/android/webkit/WebResourceRequest.html) | Object containing the details of the request. |

|                                                  Returns                                                  |
|-----------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [WebResourceResponse](https://developer.android.com/reference/android/webkit/WebResourceResponse.html)`?` | A[android.webkit.WebResourceResponse](https://developer.android.com/reference/android/webkit/WebResourceResponse.html)containing the response information or`null`if the WebView should load the resource itself. |

|                                                                                       See also                                                                                        |
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| [shouldInterceptRequest](https://developer.android.com/reference/android/webkit/WebViewClient.html#shouldInterceptRequest(android.webkit.WebView, android.webkit.WebResourceRequest)) |   |