Skip to content
This repository has been archived by the owner on Jan 24, 2020. It is now read-only.

[Questions]: How can get cookie which is set in webview in react-native? #148

Open
subhendukundu opened this issue Jun 16, 2019 · 3 comments

Comments

@subhendukundu
Copy link

subhendukundu commented Jun 16, 2019

I am trying to retrieve user entered zipcode which is added to the cookie in the webview. How do I get it? I have tried react-native-cookies which is getting an empty object not the user entered zipcode. When pass useWebKit to true and CookieManager.get('https://www.example.com', true) getting error RNCookieManagerIOS.get was called with 2 arguments but expects 1 arguments

import CookieManager from 'react-native-cookies';

componentWillMount() {
    CookieManager.get('https://www.example.com', true)
// when pass true getting error RNCookieManagerIOS.get was called with 2 arguments but expects 1 arguments
    .then((res) => {
      console.log('CookieManager.get from webkit-view =>', res);
    });
  }
}

<WebView
  style={styles.webview}
  source={{ uri: 'https://www.example.com' }}
  injectedJavaScript={INJECTED_JAVASCRIPT}
  mixedContentMode="compatibility"
  javaScriptEnabled
  domStorageEnabled
  thirdPartyCookiesEnabled
  sharedCookiesEnabled
  useWebKit
  originWhitelist={['*']}
/>

Versions

"react": "16.8.3",
"react-native": "0.59.9",
"react-native-cookies": "3.3.0"
@keyneslim
Copy link

Why are you providing the "true" , is it the value for "WebKit" ? In this case you might confused with React-Native-Cookies and React-Native-Cookie

@subhendukundu
Copy link
Author

subhendukundu commented Jun 17, 2019

Yes, I am using the true for useWebKit: bool.
Well I tried two approaches:
First:

import CookieManager from 'react-native-cookies';

componentWillMount() {
    CookieManager.get('https://www.example.com')
    .then((res) => {
      console.log('CookieManager.get from webkit-view =>', res);
// this gives me an object with the server sent cookies but not the user set zipcode
    });
  }
}

<WebView
  style={styles.webview}
  source={{ uri: 'https://www.example.com' }}
  injectedJavaScript={INJECTED_JAVASCRIPT}
  mixedContentMode="compatibility"
  javaScriptEnabled
  domStorageEnabled
  thirdPartyCookiesEnabled
  sharedCookiesEnabled
  originWhitelist={['*']}
/>

Second:

import CookieManager from 'react-native-cookies';

componentWillMount() {
    CookieManager.get('https://www.example.com', true)
// when pass true getting error RNCookieManagerIOS.get was called with 2 arguments but expects 1 arguments
    .then((res) => {
      console.log('CookieManager.get from webkit-view =>', res);
    });
  }
}

<WebView
  style={styles.webview}
  source={{ uri: 'https://www.example.com' }}
  injectedJavaScript={INJECTED_JAVASCRIPT}
  mixedContentMode="compatibility"
  javaScriptEnabled
  domStorageEnabled
  thirdPartyCookiesEnabled
  sharedCookiesEnabled
  useWebKit
  originWhitelist={['*']}
/>

According to https://github.com/joeferraro/react-native-cookies#webkit-support-ios-only, it does say to pass a bool with the url to use the webkit support.

@safaiyeh
Copy link

safaiyeh commented Jan 2, 2020

I have forked the repo here: https://github.com/safaiyeh/react-native-cookie-store
We can create issues and PRs there to continue the development of the project.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants