diff --git a/android/capacitor/src/main/java/com/getcapacitor/plugin/CapacitorCookieManager.java b/android/capacitor/src/main/java/com/getcapacitor/plugin/CapacitorCookieManager.java index 58e211fbd..bcf274e75 100644 --- a/android/capacitor/src/main/java/com/getcapacitor/plugin/CapacitorCookieManager.java +++ b/android/capacitor/src/main/java/com/getcapacitor/plugin/CapacitorCookieManager.java @@ -47,6 +47,10 @@ public CapacitorCookieManager(CookieStore store, CookiePolicy policy, Bridge bri this.serverUrl = bridge.getServerUrl(); } + public void removeSessionCookies() { + this.webkitCookieManager.removeSessionCookies(null); + } + public String getSanitizedDomain(String url) throws URISyntaxException { if (url == null || url.isEmpty()) { url = this.serverUrl; diff --git a/android/capacitor/src/main/java/com/getcapacitor/plugin/CapacitorCookies.java b/android/capacitor/src/main/java/com/getcapacitor/plugin/CapacitorCookies.java index 95a27cb0f..64f97d87a 100644 --- a/android/capacitor/src/main/java/com/getcapacitor/plugin/CapacitorCookies.java +++ b/android/capacitor/src/main/java/com/getcapacitor/plugin/CapacitorCookies.java @@ -22,10 +22,17 @@ public class CapacitorCookies extends Plugin { public void load() { this.bridge.getWebView().addJavascriptInterface(this, "CapacitorCookiesAndroidInterface"); this.cookieManager = new CapacitorCookieManager(null, java.net.CookiePolicy.ACCEPT_ALL, this.bridge); + this.cookieManager.removeSessionCookies(); CookieHandler.setDefault(this.cookieManager); super.load(); } + @Override + protected void handleOnDestroy() { + super.handleOnDestroy(); + this.cookieManager.removeSessionCookies(); + } + @JavascriptInterface public boolean isEnabled() { PluginConfig pluginConfig = getBridge().getConfig().getPluginConfiguration("CapacitorCookies");