Delete cookies from WebView

I’m using WebViews for login in to social networks like Facebook, Twitter, Windows live etc. (all based on OAuth) for posting information directly from the game. The workflow is managed server-side and also the OAuth tokens are persisted there. I provide a logout button which invalidates the OAuth tokens server side.

As it appears the WebView is actually persisting cookies permanently (so even after the application has been closed). The problem is now that on some sites the user can choose the server to remember the login based on cookies. So if the user login again it will be automatically the same user as last time and cannot change the user anymore. The only way is to de-install the app or wait until the cookie expires (which can take a long time).

Therefore can you please add a function to remove the cookies from the WebView?

On iOS it can be achieved with the following Objective-C code:

[code]
NSHTTPCookie *cookie;
NSHTTPCookieStorage *cookieJar = [NSHTTPCookieStorage sharedHTTPCookieStorage];

for (cookie in [cookieJar cookies]) {
[cookieJar deleteCookie:cookie];
}
[/code] [import]uid: 8111 topic_id: 11848 reply_id: 311848[/import]

Not sure if resurrecting old posts is frowned upon, but I have the exact same question.

Any way to clear WebView cookies?

As it stands it looks like a fresh install of the app is the only method.

Not sure if resurrecting old posts is frowned upon, but I have the exact same question.

Any way to clear WebView cookies?

As it stands it looks like a fresh install of the app is the only method.

You could possibly initiate a logout in the webview - which should then delete or expire the cookies like a normal web request would. This is similar to a browser persisting cookies and then you hitting logout and the cookies are gone. 

Hope this helps.

I’d like to renew the request for cookie deletion as well. This is not a new request, and I don’t believe our friends at Corona have ever given us an answer. Remember this thread was, ahem, started in 2011…

Its worth a check if cookies are removed when webView:removeSelf() is used? 

The above post in this thread says “WebView is actually persisting cookies permanently” even after the application is closed, and the only way to remove them “is to de-install the app or wait until the cookie expires.” Which could take until the end of the 32-bit Unix epoch in 2038 or so. :slight_smile:

You could possibly initiate a logout in the webview - which should then delete or expire the cookies like a normal web request would. This is similar to a browser persisting cookies and then you hitting logout and the cookies are gone. 

Hope this helps.

I’d like to renew the request for cookie deletion as well. This is not a new request, and I don’t believe our friends at Corona have ever given us an answer. Remember this thread was, ahem, started in 2011…

Its worth a check if cookies are removed when webView:removeSelf() is used? 

The above post in this thread says “WebView is actually persisting cookies permanently” even after the application is closed, and the only way to remove them “is to de-install the app or wait until the cookie expires.” Which could take until the end of the 32-bit Unix epoch in 2038 or so. :slight_smile:

This has been implemented and will be in build 2420.  Sample docs here: https://github.com/coronalabs/sdk-sample-deleteCookies/tree/master

When the new daily build comes out it will be documented here: http://docs.coronalabs.com/daily/api/type/WebView/deleteCookies.html

This has been implemented and will be in build 2420.  Sample docs here: https://github.com/coronalabs/sdk-sample-deleteCookies/tree/master

When the new daily build comes out it will be documented here: http://docs.coronalabs.com/daily/api/type/WebView/deleteCookies.html

I have attempted to implement this method, but it does not appear to work. I use webviews in my app to access content on a website that requires the user to log in. When logging out of my app, I would like to delete the cookies from the webview, and thus log the user out of the website as well. However, when I implement the following code, I find that I am stilled logged in:

[lua]

local webView = native.newWebView(0, 0, 1, 1)

webView:deleteCookies()

webView:removeSelf()

[/lua]

In the documentation it states that the method “deleteCookies()” deletes the cookies for all webViews, but this does not appear to be the case. 

What happens if you try the sample code here?

https://github.com/coronalabs/sdk-sample-deleteCookies/tree/master

You will probably need to change the URL…

Rob

I’ve tried the sample code and it still does not work. 

I’m using build 2014.2511

Does the deleteCookies function employ a JavaScript call?

Ok, I’ve discovered that it works on a device, but not on the simulator. 

Good to know.

I have attempted to implement this method, but it does not appear to work. I use webviews in my app to access content on a website that requires the user to log in. When logging out of my app, I would like to delete the cookies from the webview, and thus log the user out of the website as well. However, when I implement the following code, I find that I am stilled logged in:

[lua]

local webView = native.newWebView(0, 0, 1, 1)

webView:deleteCookies()

webView:removeSelf()

[/lua]

In the documentation it states that the method “deleteCookies()” deletes the cookies for all webViews, but this does not appear to be the case.