Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

`$cookies.put()` takes 30 seconds to save the cookie on disk on Android

Context:

  • We have a cordova application loading an online website. (We basically use cordova for the plugins)
  • We store a cookie using $cookies.put()
  • It works fine in desktop browsers and on iOS (as long we use expiration on the cookie)

Problem:

On Android if the user kill the application with 30 seconds after $cookies.put() is called the cookie will be gone on the next reboot.

If the user wait more than 30 seconds (like 35 seconds or more) everything works fine.

Question:

How can we force the cookie to be saved instantly (or at least much faster)?

Notes:

  • Adding options on the cookie does not change anything
  • I tried to replace the system browser with crosswalk using cordova-plugin-crosswalk-webview but it does the same thing
like image 663
jrobichaud Avatar asked Oct 04 '16 00:10

jrobichaud


2 Answers

I had the same problem and made a small plugin (still work in progress) to fix that.

It exposes the flush method, which will apply your cookie modifications (put and remove) to persistent memory.

link to cordova-plugin-cookie-manager

Feel free to contribute.

like image 166
LeBodro Avatar answered Oct 22 '22 01:10

LeBodro


The CookieManager design in the android makes it difficult to implement. The webview and the cookiemanager which contain their own in_memory databases and are in sync to one another hence there is no need to sync the two of them.

The removeSessionCookie doesn't provide a callback or any way for it to complete and since this method has been implemented in the WebView classic versions.

Here are some solutions in which you can sync up between HttpUrlCookieManager and the android webkit cookie manager

Sync up link 1

Another thing to note here is when you use $cookie.put() it defines the cookies to be sent along with the rest of the HTTP headers to the client but if you use the third party api's to get the cookies it may not contain cookies only from the client anymore which may result in unwanted side effects.

You may refer to the link here as suggested by Author to this post - author' post and here is the link for the protocols to be used while defining the cookies link here

Here is another link that i stumbled upon which may help a bit

link here

or to use the same repository/database of the webview and the HttpUrlConnection you can create your own handler as implemented in the following stack thread Stack thread

Hope it may help you a bit.

like image 22
Pritish Vaidya Avatar answered Oct 22 '22 01:10

Pritish Vaidya