Cartegraph / cordova-cookie-master

MIT License
7 stars 10 forks source link

Add getCookieValue for WKWebView #4

Open vivascau opened 4 years ago

vivascau commented 4 years ago

Hi could you please review this once you get a chance. The getCookieValue was not working for us on WKWebView and would like to still use your plugin.

Thank you.

PDLMobileApps commented 4 years ago

I tested the PR and it works with cordova-io 6.1.0 most of the time. I had some scenarios where the the getAllCookies method would return no cookies. That seems to be an issue with WkWebView and session cookies. A possible way to get it to work is use the plugin: https://github.com/CWBudde/cordova-plugin-wkwebview-inject-cookie along with this PR. In our tests, WkWebView always returned the cookies.

EDIT: I encountered issues even with the workaround above. It looks like the wbwebview stores the cookies in an unpredictable way, hence making it impossible to reliable getting the cookies.

vivascau commented 4 years ago

Hey @PDLMobileApps we actually also have a dependency in our project on that plugin (cordova-plugin-wkwebview-cookie-sync) and you also need to invoke setCookie in order to trigger the synchronisation.

As per the documentation here https://github.com/CWBudde/cordova-plugin-wkwebview-inject-cookie

See if that works or you.

With regards to this PR, I don't think that bringing in the inject cookie plugin as dependency in this plugin is required or at least not under this PR. This PR is quite specifically implementing the getCookie work to WKWebView. The issue with cookie sync should be fixed under other work mentioned above.

Hope that makes sense.

PDLMobileApps commented 4 years ago

Thanks @vivascau for the explanation. My comment above is indeed related to the getCookie function, which does not work if I use the code from the master branch and cordova-io 6.1.0. This PR makes cookie retrieval work with cordova-io 6.1.0. However, in some scenarios, the app was not able to get any session cookie on iOS even if they were set. Same app would work fine on another iOS device. Since the issue is quite random, I was under the false impression that it could be solved with the cordova-plugin-wkwebview-inject-cookie plugin. However, the issue reading session cookies in iOS appeared again on another device even when using the cordova-plugin-wkwebview-inject-cookie plugin along with cordova-cookie-master. Not sure if you have any idea on how to solve it. For now, we had to abandon the idea of getting those session cookies because of the unreliability of the solution.

vivascau commented 4 years ago

@PDLMobileApps could be something specific to your build, not sure. It works fine for me but the project is on cordova-ios 5.0.1.. It could make the difference.

Sorry I am not able to be more helpful, hope you get to the bottom of it.