# 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)

*** ** * ** ***


```
public abstract class ServiceWorkerClientCompat
```

<br />

*** ** * ** ***

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

## Summary

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

| ### Public methods |
|---|---|
| `abstract @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/webkit/WebResourceResponse.html` | `@https://developer.android.com/reference/androidx/annotation/WorkerThread https://developer.android.com/reference/androidx/webkit/ServiceWorkerClientCompat#shouldInterceptRequest(android.webkit.WebResourceRequest)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/webkit/WebResourceRequest.html request)` Notify the host application of a resource request and allow the application to return the data. |

## Public constructors

### ServiceWorkerClientCompat

Added in 1.1.0

```
public ServiceWorkerClientCompat()
```

## Public methods

### shouldInterceptRequest

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

```
@WorkerThread
public abstract @Nullable WebResourceResponse shouldInterceptRequest(@NonNull WebResourceRequest request)
```

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 `https://developer.android.com/reference/androidx/webkit/WebViewFeature#SERVICE_WORKER_SHOULD_INTERCEPT_REQUEST()` is supported. You can check whether that flag is supported using `https://developer.android.com/reference/androidx/webkit/WebViewFeature#isFeatureSupported(java.lang.String)`.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/webkit/WebResourceRequest.html request` | Object containing the details of the request. |

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/webkit/WebResourceResponse.html` | A `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 |
|---|---|
| `https://developer.android.com/reference/android/webkit/WebViewClient.html#shouldInterceptRequest(android.webkit.WebView, android.webkit.WebResourceRequest)` |   |