Skip to content

Commit

Permalink
feat: Add ResolveServiceWorkerRequests preference
Browse files Browse the repository at this point in the history
  • Loading branch information
jcesarmobile committed Feb 25, 2024
1 parent 4742358 commit b5465c1
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions framework/src/org/apache/cordova/engine/SystemWebViewClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ Licensed to the Apache Software Foundation (ASF) under one
import android.webkit.HttpAuthHandler;
import android.webkit.MimeTypeMap;
import android.webkit.RenderProcessGoneDetail;
import android.webkit.ServiceWorkerClient;
import android.webkit.ServiceWorkerController;
import android.webkit.SslErrorHandler;
import android.webkit.WebResourceRequest;
import android.webkit.WebResourceResponse;
Expand Down Expand Up @@ -116,6 +118,18 @@ public SystemWebViewClient(SystemWebViewEngine parentEngine) {
});

this.assetLoader = assetLoaderBuilder.build();
boolean setAsServiceWorkerClient = parentEngine.preferences.getBoolean("ResolveServiceWorkerRequests", false);
ServiceWorkerController controller = null;

if (setAsServiceWorkerClient) {
controller = ServiceWorkerController.getInstance();
controller.setServiceWorkerClient(new ServiceWorkerClient(){
@Override
public WebResourceResponse shouldInterceptRequest(WebResourceRequest request) {
return assetLoader.shouldInterceptRequest(request.getUrl());
}
});
}
}

/**
Expand Down

0 comments on commit b5465c1

Please sign in to comment.