[TIMOB-20075] Android: Titanium.Network.addSystemCookie not adding cookie to webview
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | n/a |
Status | Reopened |
Resolution | Unresolved |
Affected Version/s | n/a |
Fix Version/s | n/a |
Components | n/a |
Labels | Community, android, cookies, webView |
Reporter | Filipe La Ruina |
Assignee | Joshua Quick |
Created | 2015-09-22T14:24:32.000+0000 |
Updated | 2020-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).
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.
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.
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.
Hi , This is an android issue . CookieSyncManager is deprecated in API 21 Thanks
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.
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.
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