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

clearCookies()is not clearing the cache and cookies on iOS #173

Open
iniziokochi opened this issue Aug 1, 2024 · 3 comments
Open

clearCookies()is not clearing the cache and cookies on iOS #173

iniziokochi opened this issue Aug 1, 2024 · 3 comments

Comments

@iniziokochi
Copy link

I am using the plugin to load the login webpage in my app:

Application is opening the login url with method InAppBrowser.openWebView().

Before opening the web view I am calling InAppBrowser.clearCookies({url: authUrl, cache: true})

Once the login is success I am calling the InAppBrowser.close() methods and clearing all browser listeners by invoking the method InAppBrowser.removeAllListeners() from the “closeEvent” listener method.

But the clearCookies() is not clearing the cache and cookies in the iPhone devices. As the cookies and cache are not clearing properly, the session is not cleaned up and user is able to enter the app without login.

ionic 8.x
Angular 16/18
capacitor 5.x
iOS 15+

@Anthony-Matheou
Copy link

I have the same use case as you where I need the cookies/cache to clear for an authentication flow in iOS. I was able to get them to clear by changing the clearCookies function in the InAppBrowserPlugin.swift file to the following:

 @objc func clearCookies(_ call: CAPPluginCall) {
        let dataStore = WKWebsiteDataStore.default()
        let clearCache = call.getBool("cache") ?? false
        
        DispatchQueue.main.async {
            Task {
                if clearCache {
                    let cacheTypes: Set<String> = [WKWebsiteDataTypeDiskCache, WKWebsiteDataTypeMemoryCache, WKWebsiteDataTypeOfflineWebApplicationCache]
                    let caches = await dataStore.dataRecords(ofTypes: cacheTypes)
                    await dataStore.removeData(ofTypes: cacheTypes, for: caches)
                }
                
                let cookies = await dataStore.dataRecords(ofTypes: [WKWebsiteDataTypeCookies])
                await dataStore.removeData(ofTypes: [WKWebsiteDataTypeCookies], for: cookies)
                
                call.resolve()
            }
        }
    }

Not sure if this solution matches what the developers of this plugin intend this function to do, so I don't know if they will want to implement this change. But it works for what I need it to do, and sounds like it should work for you as well.

@iniziokochi
Copy link
Author

The workaround you provided to fix the clearCookie function issue on iOS is greatly appreciated, @Anthony-Matheou . Let me attempt the same thing.

@riderx
Copy link
Contributor

riderx commented Aug 30, 2024

Ok the clearCookie was a big mess since a while.
I create a clearAllCookie and clearCache method and refactored clearCookie. Then it will be easier for us to debug and improve please try 6.5.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants