From 037863bea6f3a00978125dc2f8ecba1e896c0740 Mon Sep 17 00:00:00 2001 From: Chace Daniels Date: Fri, 18 Aug 2023 10:58:36 -0700 Subject: [PATCH] fix(cookies): remove session cookies when initializing the cookie manager --- .../com/getcapacitor/plugin/CapacitorCookieManager.java | 4 ++++ .../java/com/getcapacitor/plugin/CapacitorCookies.java | 7 +++++++ 2 files changed, 11 insertions(+) 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");