-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WebView iOS cookie issue #5327
Comments
Hi @prabudevarrajan, For your convenience I am attaching sample project, you should review it. If you still facing an issue with accessing the cookies, please make the needed changes in the attached project, which will allow us to debug the case on our side. |
I was able to exactly reproduce your issue with the following changes. I added code to add cookie to native code some domain(mydomain.com) and then exactly when to same domain URL and web-view(WKWebView) is not posting all the cookies related to URL domain. But, previous "web-view" based on {"UIWebView") was posting all the domain related to the src url domain. ../Archive.2/app/main-page.ts let props = new NSDictionary([".mydomain.com", "test", "/", "test12345"], [NSHTTPCookieDomain, NSHTTPCookieName, NSHTTPCookiePath,NSHTTPCookieValue]); ../Archive.2/app/main-page.xml <WebView loaded="loadedwebview" src="https://xyz.mydomain.com/show_cookies.php" /> Now, on the show_cookies.php code, I am just printing all the cookies <?php
print_r($_COOKIE);
?> Actual Result: I am see empty cookie array Excepted Result: Should have seen cookie with "test" -> "test12345" as it belongs to same domain "mydomain.com". |
Hi @prabudevarrajan, After the replacement of UIWebView with WKWebView we could assign cookies for a specific URL, while creating new NSMutableURLRequest and setting up the needed cookies. This scenario is demonstrated in the attached sample project. Also, I will log this issue as a new feature and we will research, how this functionality could be included for iOS in NativeScript as well as how it could be done for Android. Hope this information helps |
Fixes NativeScript#5327 The solution is discussed in the following link https://stackoverflow.com/questions/26573137/can-i-set-the-cookies-to-be-used-by-a-wkwebview
Fixes NativeScript#5327 The solution is discussed in the following link https://stackoverflow.com/questions/26573137/can-i-set-the-cookies-to-be-used-by-a-wkwebview Example usage: ```xml <WebView [src]="url" syncCookies="true" cookieExpiresIn="1209600"></WebView> ``` The below two attributes are only implemented for iOS - syncCookies - Values accepted true or false. Default value is false. - cookieExpiresIn - Values specified in seconds. For eg. 1209600 seconds is equal to 14 days
This is a real blocker for us too. We have manually patched web-view-ios.js for now. |
@JPM84 : could please share how you have implemented in web-view-ios.js ?? |
Hi @bonsaibox, for our projects we forked tns-core-modules and edited /node_modules/tns-core-modules/ui/web-view/web-view.ios.js as we need our X-XSRF-TOKEN cookie. Have a look at this gist: A colleague of mine wrote a nice article on the issue (in german) as it keeps haunting us.... https://blog.coodoo.io/nativescript-setcookies-for-webview-for-android-and-ios-26d88433f812 Hope this helps. |
Fixes NativeScript#5327 The solution is discussed in the following link https://stackoverflow.com/questions/26573137/can-i-set-the-cookies-to-be-used-by-a-wkwebview
Fixes NativeScript#5327 The solution is discussed in the following link https://stackoverflow.com/questions/26573137/can-i-set-the-cookies-to-be-used-by-a-wkwebview Example usage: ```xml <WebView [src]="url" syncCookies="true" cookieExpiresIn="1209600"></WebView> ``` The below two attributes are only implemented for iOS - syncCookies - Values accepted true or false. Default value is false. - cookieExpiresIn - Values specified in seconds. For eg. 1209600 seconds is equal to 14 days
Hi, I tired to follow the solutions that proposed here, but I could not find any way to fill cookie attributes beside name and value. I did something like
Any help? |
Hi the solution before works only at first called. Hope this helps. Thanks |
anyone found a solution? |
The native method signature is Check this article here on how to have access and Intellisense for the native APIs in TypeScript. |
This is how I solved it. Template: OnNgInit:
|
Tell us about the problem
web-view for iOS is not automatically passing the cookies after the recent change of iOS UIWebView to WKWebView(#5093)
Previous Nativescript "web-view" was using UIWebView and native code cookies(using NSURLConnection/NSURISession) is shared and the application worked fine.
We are using this feature for authentication cookies to be shared between native and web-view.
Also, I don't see easy way to set the http cookie for the current NativeScript web-view ui control.
Take a look the following link for ways to set cookie for WKWebView
https://stackoverflow.com/questions/26573137/can-i-set-the-cookies-to-be-used-by-a-wkwebview
Which platform(s) does your issue occur on?
iOS
Please provide the following version numbers that your issue occurs with:
tns --version
to fetch it)node_modules/tns-core-modules/package.json
file in your project)"tns-android"
and"tns-ios"
properties in thepackage.json
file of your project)Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.
The text was updated successfully, but these errors were encountered: