Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clear cache along with cookies #85

Merged
merged 11 commits into from
Dec 31, 2023
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -259,9 +259,10 @@ Reload the current web page.

#### ClearCookieOptions

| Prop | Type |
| --------- | ------------------- |
| **`url`** | <code>string</code> |
| Prop | Type |
| ----------- | -------------------- |
| **`url`** | <code>string</code> |
| **`cache`** | <code>boolean</code> |


#### HttpCookie
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ public void open(PluginCall call) {
@PluginMethod
public void clearCookies(PluginCall call) {
String url = call.getString("url");
Boolean clearCache = call.getBoolean("cache", false);
if (url == null || TextUtils.isEmpty(url)) {
call.reject("Invalid URL");
} else {
Expand All @@ -201,6 +202,9 @@ public void clearCookies(PluginCall call) {
url,
cookieName + "=; Expires=Thu, 01 Jan 1970 00:00:01 GMT"
);
if (clearCache) {
cookieManager.removeSessionCookie();
}
}
}
call.resolve();
Expand Down
5 changes: 5 additions & 0 deletions ios/Plugin/InAppBrowserPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ public class InAppBrowserPlugin: CAPPlugin {
@objc func clearCookies(_ call: CAPPluginCall) {
let dataStore = WKWebsiteDataStore.default()
let urlString = call.getString("url") ?? ""
let clearCache = call.getBool("cache") ?? false

if clearCache {
URLCache.shared.removeAllCachedResponses()
}

guard let url = URL(string: urlString), let hostName = url.host else {
call.reject("Invalid URL")
Expand Down
1 change: 1 addition & 0 deletions src/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export interface GetCookieOptions {

export interface ClearCookieOptions {
url: string;
cache?: boolean;
}

export interface OpenOptions {
Expand Down
Loading