Bug 177478 - WKWebView XHR cookies not remembered until app is backgrounded
Summary: WKWebView XHR cookies not remembered until app is backgrounded
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKit2 (show other bugs)
Version: Safari Technology Preview
Hardware: iPhone / iPad iOS 11
: P2 Normal
Assignee: Nobody
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2017-09-25 18:21 PDT by Grant Patterson
Modified: 2019-10-07 14:34 PDT (History)
12 users (show)

See Also:


Attachments
wkwebview session storage glitch app example (1.61 MB, application/octet-stream)
2019-09-27 10:58 PDT, tleach
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Grant Patterson 2017-09-25 18:21:13 PDT
This is related to Bug 140191 but while there seems to be basic cookie access now available in WKWebView, it doesn't work on initial app load.

Steps to Reproduce:
- Create a trivial WKWebView app (mine is a Cordova app using WKWebView)
- In javascript, execute an XHR that receives a session cookie
- Execute another XHR and notice that the session cookie is not sent
- Background, then foreground the app
- Now it will work as expected

I've worked around this by executing an XHR in native code before attempting further XHRs in javascript, but even then, I must wait ~2s before attempting the XHR in javascript. Otherwise the cookies seem to be forgotten again, indefinitely, until either the app is backgrounded or I wait long enough after the native-code XHR.
Comment 2 Radar WebKit Bug Importer 2017-09-27 17:40:32 PDT
<rdar://problem/34702882>
Comment 3 Geoffrey Garen 2017-12-01 17:31:03 PST
We know that XHR can set a session cookie in Safari. So we need a more complete description or a test application to demonstrate a case where XHR can’t set a session cookie.

Can you upload a test app demonstrating this bug?
Comment 4 Ross 2019-06-02 16:17:13 PDT
This is still an issue, is there any update? I see a previous comment was looking for a sample app, is that still desired in order for the webkit team to investigate?

It seems like cookies from XHR requests aren't reliably set to the WK cookie store (backgrounding or restarting the app seems to sync them). Good description here: https://stackoverflow.com/a/49534854/2757879

Also some related/relevant discussion for Ionic/Cordova users: https://github.com/ionic-team/cordova-plugin-ionic-webview/issues/22

I'd like to know what I can do to help get this one resolved. Thanks!
Comment 5 tleach 2019-09-27 10:58:19 PDT
Created attachment 379741 [details]
wkwebview session storage glitch app example

Attached is a simple Cordova app that attempts to incorporate the wkwebview engine. We're currently trying to switch from uiwebview to fix issues with iOS video playback, but are having issues with the users not being able to log in on the initial app launch.

username: injoytester@gmail.com
password: password
Comment 6 Niklas Merz 2019-09-27 16:02:06 PDT
(In reply to tleach from comment #5)
> Created attachment 379741 [details]
> wkwebview session storage glitch app example
> 
> Attached is a simple Cordova app that attempts to incorporate the wkwebview
> engine. We're currently trying to switch from uiwebview to fix issues with
> iOS video playback, but are having issues with the users not being able to
> log in on the initial app launch.

If your login issues are related to cookies please check this issue: https://bugs.webkit.org/show_bug.cgi?id=200857
Comment 7 Geoffrey Garen 2019-10-07 14:34:27 PDT
Sorry, I meant source code that conforms to the original description:

Steps to Reproduce:
- Create a trivial WKWebView app (mine is a Cordova app using WKWebView)
- In javascript, execute an XHR that receives a session cookie
- Execute another XHR and notice that the session cookie is not sent
- Background, then foreground the app
- Now it will work as expected