# WKWebView and cookies

**URL:** <https://forum.ionicframework.com/t/wkwebview-and-cookies/200679>\
**Category:** ionic-v3\
**Created:** [December 3, 2020, 7:43pm UTC](https://forum.ionicframework.com/t/wkwebview-and-cookies/200679 "2020-12-03T19:43:51Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![helpmelearn](https://avatars.discourse-cdn.com/v4/letter/h/f0a364/32.png) [@helpmelearn](https://forum.ionicframework.com/u/helpmelearn)\
**Post date:** [December 3, 2020, 7:43pm UTC](https://forum.ionicframework.com/t/wkwebview-and-cookies/200679/1 "2020-12-03T19:43:51Z")

</div>

Trying to go through the upgrade to WKWebView.  
Doing the final round of testing and found a bug trying to use JavaScript document.cookie to set a temporary cookie. The reason I’m using a cookie is so I can set an expire date and prompt user again.

Cant find a way to get Javascript document.cookie to work in the new WKWebView version.  
Any idea?

---

<div class="post-metadata">

**Author:** ![Alisonsi](https://avatars.discourse-cdn.com/v4/letter/a/7cd45c/32.png) [@Alisonsi](https://forum.ionicframework.com/u/Alisonsi)\
**Post date:** [December 4, 2020, 2:14am UTC](https://forum.ionicframework.com/t/wkwebview-and-cookies/200679/2 "2020-12-04T02:14:29Z")

</div>

You can test [https://github.com/psirenny/cordova-plugin-wkwebview-sync-cookies#readme](https://github.com/psirenny/cordova-plugin-wkwebview-sync-cookies#readme)  
and [https://www.npmjs.com/package/cordova-plugin-wkwebview-inject-cookie](https://www.npmjs.com/package/cordova-plugin-wkwebview-inject-cookie)

---

<div class="post-metadata">

**Author:** ![helpmelearn](https://avatars.discourse-cdn.com/v4/letter/h/f0a364/32.png) [@helpmelearn](https://forum.ionicframework.com/u/helpmelearn)\
**Post date:** [December 4, 2020, 3:19pm UTC](https://forum.ionicframework.com/t/wkwebview-and-cookies/200679/3 "2020-12-04T15:19:15Z")

</div>

Thanks for the suggestions.  
I’m really confused why there is not a more official fix for these issues from either Cordova or Ionic.

**Issue 1** - Can’t set cookies from within WKWebView – document.cookie no longer works when using WKWebView. No official ionic fix? Nothing I can see in Ionic WKWebView documentation that warns about this problem with the upgrade to WKWebView (maybe it started in ios 11?)  
Is there a way to allow cookies to be set. The only work around is to use local storage. I think?

**Issue 2** - Setting cookies fails on first load of app and first call with an API request. Seems to be an issue with WKWebView cookie manager (whatever it is call). I don’t know if its an initialization or timing issue.

Some of the suggested plugins seem to be forks of others. Not sure which one is the best to use and why?  
Other suggestion is to go back to use local storage. The only way to read set-cookie from a request is allow from the server side.

access-control-expose-headers: Set-Cookie

I’m not sure of the security implications of doing such.

Is there any “official” fix for these issues?

---

<div class="post-metadata">

**Author:** ![Alisonsi](https://avatars.discourse-cdn.com/v4/letter/a/7cd45c/32.png) [@Alisonsi](https://forum.ionicframework.com/u/Alisonsi)\
**Post date:** [December 14, 2020, 1:49pm UTC](https://forum.ionicframework.com/t/wkwebview-and-cookies/200679/4 "2020-12-14T13:49:56Z")

</div>

Hello I remember this plugin [https://github.com/silkimen/cordova-plugin-advanced-http](https://github.com/silkimen/cordova-plugin-advanced-http) ,  
you can test the operation setcookie =\> [https://github.com/silkimen/cordova-plugin-advanced-http#setcookie](https://github.com/silkimen/cordova-plugin-advanced-http#setcookie), I am not used, I thing you can help.

---

<div class="post-metadata">

**Author:** ![helpmelearn](https://avatars.discourse-cdn.com/v4/letter/h/f0a364/32.png) [@helpmelearn](https://forum.ionicframework.com/u/helpmelearn)\
**Post date:** [December 16, 2020, 6:49pm UTC](https://forum.ionicframework.com/t/wkwebview-and-cookies/200679/5 "2020-12-16T18:49:27Z")

</div>

> [@Alisonsi](#):
>
> [cordova-plugin-wkwebview-inject-cookie - npm](https://www.npmjs.com/package/cordova-plugin-wkwebview-inject-cookie)

Thanks.  
Furstrted there is not offical fix.  
I was using this plugin  
cordova-plugin-wkwebview-inject-cookie (or some version of it).  
Worked fine in IOS 13.5 but does not work in ios 14+. I’m starting over.  
Most of these plugins were written years ago. I don’t like using old plugins if I don’t have to.

Anybody have cookies working on startup with IOS 14+ ???

---

<div class="post-metadata">

**Author:** ![achakra21](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/achakra21/32/137725_2.png) [@achakra21](https://forum.ionicframework.com/u/achakra21)\
**Post date:** [February 22, 2021, 6:13am UTC](https://forum.ionicframework.com/t/wkwebview-and-cookies/200679/6 "2021-02-22T06:13:04Z")

</div>

Bu in this plugin if you clear the app from background , use clearCookies() method it doesn’t works in IOS
