-
Notifications
You must be signed in to change notification settings - Fork 140
Can't get cookies on iOS #47
Comments
Just making sure you're awaiting the promise? It's possible the cookies are "sandboxed" somehow. Would need to dig in but if anyone else has ideas please chime in |
I have this same issue. Here are my dependencies: The code I'm using:
From what I can tell there are no errors, it simply doesn't work on the iOS device and on the iOS simulator. This code does work on Web. |
@tafelnl Is this an issue your implementation would fix? |
Well, yes and no. It's complicated and I am not a native developer. But I will do my best to explain: Android vs iOSFirst of all we have to distinguish between Android and iOS. On Android everything works just fine, with only one caveat:
On iOS, cookies do not work at all or not correctly (dependent on your setup and use). Therefore, the rest of this comment considers iOS. Client vs Server sideNext we need to distinguish between client side and server side cookies. In an ideal world cookies would work as follows: Client side cookies can be set by: Server side cookies will be set by making use of Headers: If you use the flag Now, as we know, cookies unfortunately do not behave like this on iOS. This is probably because of the fact that a custom scheme is used ( So the next step is to discover how they exactly do behave. When do Client side cookies work on iOS?The answer is quite simple: never. It's easy to reproduce this. Try running When do Server side cookies work on iOS?When you have your app configured as follows:
It will work exactly the same as if you would visit http://example.com in Safari on your Mac or iPhone. But since such a configuration is only for development purposes you config would probably look like this:
This configuration makes your app launch from But (understandably) iOS does not consider What is remarkable is that iframes that are secure (e.g.: https://tr.snapchat.com for tracking) within the webview also seem to be considered insecure by iOS. Because they are also not able to retrieve cookies through a So how to fix all of this? How to fix the Client side cookies on iOS?This is pretty straight forward. As explained in my other comment (ionic-team/capacitor#1373 (comment)) we will have to proxy the So not to worry about client side cookies, they can be fixed pretty easily. How to fix the Server side cookies on iOS?On to Server side cookies. Again I am not a native developer. But I did some digging and came up with a few ideas. The most straight forward (and also the worst) solution is by using a config similar to the following:
With This is of course not a viable solution in any way. It has many defects and use cases where this is not a working fix. So what to do now? I've got some (still vague) ideas about how to fix this: A possible solution would be to add afterhooks to both the Another solution would be to add beforehooks to both the Last solution I had in mind, was to intercept all Also worth noting is that the Cordova community is bothered by the same issues. A lot of information can be found there. See for example this library: https://github.com/CWBudde/cordova-plugin-wkwebview-inject-cookie. Although I do not understand what problem this library is trying to solve in what way exactly. It might be worth looking at. |
Is there any update on this topic. Or is Set-Cookie a lost cause for iOs? |
I'm closing this issue for now because this is mainly an issue with Capacitor Core. The team is aware and actively working on solutions, but for now it is outside the scope of this plugin due to limitations set by Apple with Third Party cookies |
On second thought, I'll leave it open, but label it appropriately |
This is fixed as best as it can be in this plugin. The issue is open in core, but with the recent 1.0 release of this plugin you can specify the domains you need cookies from and it may fit your use case. Alternatively you can change the |
Question
I'm here because of the wkwebview issue of getting and setting cookies and hoped that this plugin will resolve this problems.
So i tried the Http.getCookie({url: ....}) method but the result is every time an empty array.
The first request to an IDP is done via an other framework so not with the Http Plugin. The IDP is setting the cookie. But it is not seen in Developer Console with Chrome when debugging on mobile. The cookie is seen when hosting the app in real browser but there also the plugins Http.GetCookie method returns an empty array.
So my Question is how to receive Cookies from other websites and send them with request to the same website?
I hope you can help me
The text was updated successfully, but these errors were encountered: