cordova-plugin-ionic-webview icon indicating copy to clipboard operation
cordova-plugin-ionic-webview copied to clipboard

Cookies Ignored on First Application Execution

Open doverdb12 opened this issue 8 years ago • 75 comments

When installing a fresh build of my application and attempting to log in, it fails because the authentication cookie sent by the server is never stored. Closing the application and re-launching fixes the issue. There is an identical issue for cordova-plugin-wkwebview-engine here. Is this one of the issues that has been / will be fixed in this fork, or is there a viable workaround at this time?

doverdb12 avatar Oct 12 '17 18:10 doverdb12

I have the same issue, cookies not working the first time.

lucasforchino avatar Oct 18 '17 20:10 lucasforchino

Same issue here. I don't think there is a solution in this fork. This is really a blocker for us in user experience. Please take a look at this!

SpellChucker avatar Oct 18 '17 20:10 SpellChucker

This also causes websockets to break on many apps that rely on sticky session cookies to connect to the same server. Even if you were to use localstorage for auth, it's hard to get around the sticky session issue.

psirenny avatar Oct 23 '17 17:10 psirenny

This fork seems to have fix for this issue: https://github.com/agarcia17/cordova-plugin-wkwebview-engine It is behind the current master of the plugin though.

mukana-lahtelat avatar Oct 27 '17 10:10 mukana-lahtelat

Yikes, that is one heavy handed fix.

psirenny avatar Oct 27 '17 11:10 psirenny

@mukana-lahtelat I don't think this fixes XHR requests, it seems to only deal with the loadRequest lifecycle, meaning on raw page loads it will re-inject the cookies. The better fix for non-XHR requests is outlined here.

SpellChucker avatar Oct 27 '17 17:10 SpellChucker

I also seem to be experiencing this issue, but for me the cookies don't ever seem to be sent or stored even when I restart the application (using a simulator). I can see Set-Cookie is being sent back properly, and this all works fine in UIWebView, but for WKWebView the cookies never seem to be stored at all.

ajcrites avatar Nov 03 '17 04:11 ajcrites

+1. Because of the cookie issue, I had to uninstall the WKWebView plugin. Any solutions?

beckson avatar Nov 15 '17 03:11 beckson

+1 Still having this issue! Went back to UIWebView

kas84 avatar Nov 21 '17 16:11 kas84

+1 Is it something what is going to be fixed in this plugin pretty soon?

mezykr avatar Dec 04 '17 12:12 mezykr

I uninstall WKWebView plugin then reinstall ios platform, so it working now.

htcholdingsvn avatar Dec 07 '17 02:12 htcholdingsvn

This appears to be causing problems for me as well

redgeoff avatar Dec 07 '17 22:12 redgeoff

When you will call first the same request using cordova-plugin-fetch, it will "unlock" saving set-cookie header in next normal request. That fixes issue when app is opened first time after installation. But it's not so elegant solution ;) ...

mezykr avatar Dec 08 '17 15:12 mezykr

I'm using in my app cordova-plugin-file-transfer to download/save files on device. In request there is no cookie header, even when app is not first opened on device. Looks like above solution with cordova-plugin-fetch solves that issue .. Maybe it will help someone to better investigate and solve that issue.

mezykr avatar Dec 11 '17 11:12 mezykr

+1 mindf**k

edit: @mezykr your solution worked, thanks. I also found this https://github.com/psirenny/cordova-plugin-wkwebview-sync-cookies that I believe does the same thing under the hood.

alonp99 avatar Dec 19 '17 15:12 alonp99

What happened to the PR ? Did it work? Why was it not merged?

oliverjanik avatar Jan 15 '18 00:01 oliverjanik

Has anyone found a fix for this issue that is not listed here? Is anyone from Ionic working on this at all?

scottopolis avatar Jan 22 '18 16:01 scottopolis

+1 Would also love to see a working fix!

schostin avatar Jan 24 '18 09:01 schostin

+1 Please fix this issue.

johnnyshields avatar Jan 25 '18 07:01 johnnyshields

I've made a workaround for this so that the cookies work again after the first startup of the app. For that I created this plugin based on a different persons advice. If i find the Person again ill give him credit here and in the plugin of course:

https://github.com/COMLINE-AG/native-xhr-plugin/

This will make the use of cookies possible again.

thuelsmeier avatar Feb 01 '18 12:02 thuelsmeier

So do a native request and wait 3 seconds? Really?

oliverjanik avatar Feb 02 '18 00:02 oliverjanik

@oliverjanik Well there is no real alternative for this until Ionic fixed this issue. I've tried many workarounds, but this workaround was the only one that worked.

If u have concerns about the 3 seconds of waiting, then make a request on application startup. If the user has to enter login data then the 3 seconds have passed already and the user will notice nothing about it.

Edit: I forgot to mention that u need to do this native request once. After this request and the wait of 3 seconds u can use normal xhr again.

thuelsmeier avatar Feb 02 '18 09:02 thuelsmeier

I tried most of the wkwebview xhr workarounds and went with this one: https://github.com/sortdinc/cordova-plugin-wkwebview-ionic-xhr

The plugin caches cookies at the native layer between requests but it does not attempt to sync cookies between the WKWebView and the native sessions. From the JavaScript context, this means "document.cookie" won't contain any cookies returned from XHR handled at the native layer and the native iOS XHR will not see any cookies returned from remote resources fetched by the browser context, such as images.

asrytis avatar Feb 02 '18 10:02 asrytis

@asrytis do you use that to do all you ajax calls then?

oliverjanik avatar Feb 03 '18 00:02 oliverjanik

Are there any news on this?

Abildtoft avatar Mar 08 '18 10:03 Abildtoft

I think you need to get Apple to fix their Webview, to solve this, cleanly.

oliverjanik avatar Mar 09 '18 02:03 oliverjanik

Any updates on this?

Can confirm otherwise that https://github.com/sortdinc/cordova-plugin-wkwebview-ionic-xhr suggested by @asrytis seems to do the trick in the meantime!

JulianLaval avatar Mar 29 '18 16:03 JulianLaval

I can also confirm that the fork mentioned by @asrytis works with cookies on first app startup. However, there are issues playing media files, it seems there are still several major issues with the WK Webview that are not resolved https://issues.apache.org/jira/browse/CB-10141?jql=project%20%3D%20CB%20AND%20status%20%3D%20Open%20AND%20labels%20%3D%20wkwebview-known-issues

scottopolis avatar Mar 29 '18 16:03 scottopolis

Here you write: "We wanted to make sure that people could easily switch to WKWebView without many issues, but there are still some things that you’ll need to consider." Why isn't it solved already??? This is already noticed in 2014

odejonge avatar Apr 04 '18 10:04 odejonge

I have the same problem here. Cookies do not work the first time. If I kill and reopen the application, it works ...

kbrin423 avatar May 09 '18 14:05 kbrin423