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

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.

import CookieManager from 'react-native-cookies';

componentWillMount() {
    CookieManager.get('https://www.example.com')
    .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
  originWhitelist={['*']}
/>

I am trying out in iOS simulator. I see #175 as merged but cant figure out how to use it.

2 thoughts on “[Questions]: How can get cookie which is set in webview in react-native?

  1. You can use the injectedJavaScript or injectJavaScript method as per the documentation

    const getCookiesJS = "ReactNativeWebView.postMessage(document.cookie)";
    return (
      <WebView 
          injectedJavaScript={getCookiesJS}
          onMessage={event => console.log(event.nativeEvent.data)}
          source={{ uri: "https://www.example.com" }}
          javaScriptEnabled={true}
      />
    );