You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by GitBox <gi...@apache.org> on 2019/06/19 16:20:44 UTC

[GitHub] [cordova-plugin-wkwebview-engine] EiyuuZack opened a new issue #100: Setting cookies in native code does not update document.cookie

EiyuuZack opened a new issue #100: Setting cookies in native code does not update document.cookie
URL: https://github.com/apache/cordova-plugin-wkwebview-engine/issues/100
 
 
   # Bug Report
   
   ## Problem
   I have an iOS Cordova application where I need to intercept requests. I have extended `CDVWKWebViewEngine` to set a custom scheme handler
   
   ```
   - (WKWebViewConfiguration*) createConfigurationFromSettings:(NSDictionary*)settings{
       WKWebViewConfiguration *configuration = [super createConfigurationFromSettings:settings];
       
       [configuration setURLSchemeHandler:self forURLScheme:@"myapp"];
       
       return configuration;
   }
   ```
   
   My Cordova app loads using that scheme in order to intercept the first (and following) requests. I have the following in my `config.xml` file
   
   ```
   <content src="myapp://host.domain.com/app/" />
   <allow-navigation href="myapp://*/*" />
   ```
   
   After intercepting and the request in [startURLSchemeTask](https://developer.apple.com/documentation/webkit/wkurlschemehandler/2890834-webview?language=objc), I massage the request as required, replace `myapp` with `https` and send it using `NSURLSessionDataTask`.
   
   Upon receiving the response I just pass it on to the WKWebView. When a response contains a `Set-Cookie` header I expect the cookie to be set by the WKWebView.
   
   Example cookie header:
   `Set-Cookie: foo=bar; Domain=host.domain.com; Path=/`
   
   However the Safari inspector shows no cookie and `document.cookie` is always empty.
   
   ### What is expected to happen?
   The cookie is set by WKWebView shows in Safari inspector and it can be accessed through `document.cookie`.
   
   
   ### What does actually happen?
   The cookie is **not** shown in Safari inspector and `document.cookie` returns **empty**. In fact just trying to do `document.cookie="name=value"` _directly_  in the Safari inspector does nothing -- `document.cookie` still returns `""`.
   
   
   ## Information
   <!-- Include all relevant information that might help understand and reproduce the problem -->
   The `Set-Cookie` header is present in the response that is passed onto the WKWebView.
   <img width="703" alt="Screenshot 2019-06-19 at 16 43 14" src="https://user-images.githubusercontent.com/996955/59781702-40c60a80-92b4-11e9-8acd-f410f2440af4.png">
   
   
   
   ### Command or Code
   <!-- What command or code is needed to reproduce the problem? -->
   
   1. Load the app using a custom scheme (e.g. `myscheme`).
   
   1. Attach and open the Safari inspector and validate `window.origin` starts with `mycheme://...` and that `document.domain` is correct (`host.domain.com` in my example)
   
   1. Perform a XHR request to a `myscheme://url` that returns a cookie like in the example above. Intercept the request, change the scheme to `https`, send it using `NSURLSessionDataTask` and return the response to WKWebView.
   
   1. In Safari inspector check the request & response presence in the `Network` tab
   
   1. Open `Storage` tab and validate the cookie returned in the header is missing
   
   1. Type `document.cookie` in console and it will return `""`
   
   1. Optional: type `document.cookie="foo=bar"` and validate it remains empty
   
   
   ### Environment, Platform, Device
   <!-- In what environment, on what platform or on which device are you experiencing the issue? -->
   iPhone device or simulator -- happens anywhere.
   
   ### Version information
   <!-- 
   What are relevant versions you are using?
   For example:
   Cordova: Cordova CLI, Cordova Platforms, Cordova Plugins 
   Other Frameworks: Ionic Framework and CLI version
   Operating System, Android Studio, Xcode etc.
   -->
   cordova-cli 9.0.0
   cordova-ios 4.5.5
   Xcode 10.2.1
   
   
   ## Checklist
   <!-- Please check the boxes by putting an x in the [ ] like so: [x] -->
   
   - [x] I searched for existing GitHub issues
   - [ ] I updated all Cordova tooling to most recent version
   - [x] I included all the necessary information above
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org