question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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 https://github.com/react-native-community/react-native-webview/pull/175 as merged but cant figure out how to use it.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:6

github_iconTop GitHub Comments

10reactions
TiagoHellebrandtcommented, Jul 31, 2019

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}
  />
);
8reactions
cgfeelcommented, Sep 18, 2019

@TiagoHellebrandt Can’t get HTTPOnly Cookies

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can get cookie which is set in webview in react-native ...
I have tried react-native-cookies which is getting an empty object not the user entered zipcode. import CookieManager from 'react-native-cookies ...
Read more >
How can get cookie which is set in webview in react-native?
You can try the following trick without using any native modules. just go through the Code or URL. // @flow import React, {...
Read more >
@react-native-cookies/cookies - npm
Start using @react-native-cookies/cookies in your project by running `npm i @react-native-cookies/cookies`. There are 11 other projects in ...
Read more >
How to communicate with data between WebViews in React ...
First, go to the terminal and create a react-native application. npx react-native init webviewdata ... How to send data from WebView to a...
Read more >
set-cookie header not working react - You.com | The AI Search ...
You can't set cookies for another domain, as it would be a huge security problem to do so. In your case, the first...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found