Skip to content
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

Cookies/localStorage is not shared across WKWebView:s #68

Closed
epiceros opened this issue Oct 2, 2018 · 10 comments
Closed

Cookies/localStorage is not shared across WKWebView:s #68

epiceros opened this issue Oct 2, 2018 · 10 comments

Comments

@epiceros
Copy link

epiceros commented Oct 2, 2018

I opened an issue here:
facebook/react-native#21450

Is this something that needs to be addressed here as well?

@felixmeziere
Copy link

This is blocking us too :/

@Titozzz
Copy link
Collaborator

Titozzz commented Oct 3, 2018

Can you give more details about your environment? Does this only apply to wkwebview? Is it fine on Android and UIWebview ? Do you have multiples Webview a t the same time or only one that you close then reopen ?

@epiceros
Copy link
Author

epiceros commented Oct 3, 2018

Hi! Some more info. We have an app with one main webview where, the user logs in. Then at times we overlay that webview with another webview, where the user needs to be logged in (so they are both open at the same time, and they are on the same domain). The webview displays fine, but the user is not logged in, in the overlaying webview. This is only the case for WKWebView, in UIWebView, and on Android, it just works.

@Titozzz
Copy link
Collaborator

Titozzz commented Oct 3, 2018

Ok, thanks for the details. If you want to start working on it I can review / merge pull requests 🚀

@felixmeziere
Copy link

felixmeziere commented Oct 3, 2018

@epiceros @Titozzz found an improvable fix for this for now:

  • Add master branch of react-native-cookies to your package.json: "react-native-cookies: "git+https://github.com/joeferraro/react-native-cookies"
  • Install/link the library properly.
  • Get the cookies of the website you need and then set them with the hidden option useWebKit set to true.
const cookies = await CookieManager.get('http://example.com')
CookieManager.set({
  name: 'myCookie',
  value: cookies.myCookie.value,
  domain: cookies.myCookie.domain,
  origin: cookies.myCookie.domain,
  path: cookies.myCookie.domain.path,
  version: '1',
  expiration: cookies.myCookie.expiresDate
}, true) // <= true here!!!

You might just need the set part.
Not sure of what's really needed and not in this, I don't have time to investigate more on it. If you find a quicker way of doing it please tell us here :-)

@Titozzz
Copy link
Collaborator

Titozzz commented Oct 3, 2018

Good insight, thanks

@finalquest
Copy link

Me again.
We have been strugling with cookies errors on wkwebview from the start.
The way wkwebview handles cookies on iOS is pretty rare.
In the old UIWebview, the cookies are shared between all the network requests of the application.
So, for example, I logged to a server using fetch on RN, the webview can keep a session without login, because the cookie session is already setted by the first fetch.

WKWebview dosnt work like this. I've made several attempst to fix that on the react-native-wkwebview repo, but I failed every time.

So, if anyone has any insight on this, I will gladly accept it

Regards

@KoenLav
Copy link

KoenLav commented Oct 21, 2018

This should already be fixed here:

CRAlpha/react-native-wkwebview@3e01629

Please consider replacing WKWebView with this better maintained version, per my suggestion here: #105

kylemantesso added a commit to kylemantesso/react-native-webview that referenced this issue Nov 15, 2018
@kylemantesso
Copy link
Contributor

I've raised a PR to fix this issue

Titozzz pushed a commit that referenced this issue Jan 7, 2019
…are shared across webviews in iOS (#138)

* fix(WKWebview): [iOS] Add shared process pool so cookies and localStorage are shared across webviews (#68)

* Add optional shared process pool

BREAKING CHANGE: useSharedProcessPool prop is set to true by default. If you want the old behavior, please use useSharedProcessPool={false}
Titozzz pushed a commit that referenced this issue Jan 7, 2019
# [3.0.0](v2.15.0...v3.0.0) (2019-01-07)

### Features

* **WKWebview:** Add shared process pool so cookies and localStorage are shared across webviews in iOS ([#138](#138)) ([afadc62](afadc62)), closes [#68](#68)

### BREAKING CHANGES

* **WKWebview:** useSharedProcessPool prop is set to true by default. If you want the old behavior, please use useSharedProcessPool={false}
@github-actions
Copy link

github-actions bot commented Sep 2, 2019

Hello 👋, this issue has been opened for more than 2 months with no activity on it. If the issue is still here, please keep in mind that we need community support and help to fix it! Just comment something like still searching for solutions and if you found one, please open a pull request! You have 7 days until this gets closed automatically

@github-actions github-actions bot added the Stale label Sep 2, 2019
phuongwd pushed a commit to phuongwd/react-native-webview that referenced this issue Apr 29, 2020
…are shared across webviews in iOS (react-native-webview#138)

* fix(WKWebview): [iOS] Add shared process pool so cookies and localStorage are shared across webviews (react-native-webview#68)

* Add optional shared process pool

BREAKING CHANGE: useSharedProcessPool prop is set to true by default. If you want the old behavior, please use useSharedProcessPool={false}
phuongwd pushed a commit to phuongwd/react-native-webview that referenced this issue Apr 29, 2020
# [3.0.0](react-native-webview/react-native-webview@v2.15.0...v3.0.0) (2019-01-07)

### Features

* **WKWebview:** Add shared process pool so cookies and localStorage are shared across webviews in iOS ([react-native-webview#138](react-native-webview#138)) ([afadc62](react-native-webview@afadc62)), closes [react-native-webview#68](react-native-webview#68)

### BREAKING CHANGES

* **WKWebview:** useSharedProcessPool prop is set to true by default. If you want the old behavior, please use useSharedProcessPool={false}
noproblem23 added a commit to noproblem23/react-native-webview that referenced this issue Apr 18, 2023
# [3.0.0](react-native-webview/react-native-webview@v2.15.0...v3.0.0) (2019-01-07)

### Features

* **WKWebview:** Add shared process pool so cookies and localStorage are shared across webviews in iOS ([#138](react-native-webview/react-native-webview#138)) ([afadc62](react-native-webview/react-native-webview@afadc62)), closes [#68](react-native-webview/react-native-webview#68)

### BREAKING CHANGES

* **WKWebview:** useSharedProcessPool prop is set to true by default. If you want the old behavior, please use useSharedProcessPool={false}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants