Skip to content

Commit

Permalink
feat: Add ResolveServiceWorkerRequests preference (#1696)
Browse files Browse the repository at this point in the history
* feat: Add ResolveServiceWorkerRequests preference
* Change default to true
  • Loading branch information
jcesarmobile authored May 8, 2024
1 parent 9261b29 commit ebf0b10
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", true);
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 ebf0b10

Please sign in to comment.