Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-20075] Android: Titanium.Network.addSystemCookie not adding cookie to webview

GitHub Issuen/a
TypeBug
Priorityn/a
StatusReopened
ResolutionUnresolved
Affected Version/sn/a
Fix Version/sn/a
Componentsn/a
LabelsCommunity, android, cookies, webView
ReporterFilipe La Ruina
AssigneeJoshua Quick
Created2015-09-22T14:24:32.000+0000
Updated2020-08-18T20:42:48.000+0000

Description

On SDK 5.0 Titanium.Network.addSystemCookie doesn't work as expected when trying to add cookies to a webview. In SDK 3.5 our code works fine. The use case is that a login is done in the main app and the session cookie returned needs to be used on our webviews. Here is the code that does that.
if (osname === 'android') {
    var sessionCookie = _.findWhere(
        Titanium.Network.getHTTPCookiesForDomain(
            Ti.App.Properties.getString('siteUrl').match(/^https?:\/\/(?:www\.)?([^\/^:]+)[:\/$]?/i)[1]
        ),
        {name: 'JSESSIONID'}
    );
    Titanium.Network.removeAllSystemCookies();
    Titanium.Network.addSystemCookie(sessionCookie);
}
I have confirmed that sessionCookie is correct and that it is not being used in the webview (using chrome inspect a simple ajax request doesn't send the cookie). This used to work fine on 3.5 (not sure about 4 though, we migrated 3.5 -> 5).

Comments

  1. Filipe La Ruina 2015-09-22

    Just noticed this is a problem with android target 21 instead of 19 (we had to change it for the new SDK). If I use sdk 3.5 on target 21 the same problem happens. Target 19 works fine using sdk 3.5.
  2. Ingo Muschenetz 2015-09-22

    CookieSyncManager is deprecated in API 21: http://developer.android.com/reference/android/webkit/CookieSyncManager.html. See https://github.com/appcelerator/titanium_mobile/blob/master/android/modules/network/src/java/ti/modules/titanium/network/NetworkModule.java#L502. However deprecated is different than removed.
  3. Filipe La Ruina 2015-09-22

    That is even stranger since it says in the android docs that it will "automatically sync cookies as necessary". The cookies set in http request in the app aren't used in webviews.
  4. Aminul Islam 2015-11-02

    Hi , This is an android issue . CookieSyncManager is deprecated in API 21 Thanks
  5. Filipe La Ruina 2015-11-23

    So what's the solution? Titanium uses a deprecated/not working feature, what is the alternative here? SDK 5 requires android 21 so this should be addressed somehow, even if that means you don't support sharing cookies anymore. Closing this as "Not Our Bug" is the worst way of "solving" a problem.
  6. Ingo Muschenetz 2015-11-23

    I agree. According to the docs, this should "just work" even with a deprecated method. It is possible it is an actual Google bug however, but the auto-sync stuff should work.
  7. Nikos Poulios 2017-06-29

    I noticed that android get/addSystemCookie is not working on Android 6.1.0.GA. After some testing I found out that those functions were not working on previous versions either (5.4.1/6.0.4) but it was noticed now in 6.1.0.GA, because I suppose that cookies were auto synced with the webview and in 6.1.0.GA cookies are not available after you restart the app

JSON Source