You can try the following trick without using any native modules. just go through the Code or URL.

// @flow

import React, { Component } from 'react';
import {
  WebView,
} from 'react-native';

class LoginScreen extends Component {
  state = {
    cookies    : {},
    webViewUrl : ''
  }

  onNavigationStateChange = (webViewState: { url: string }) => {
    const { url } = webViewState;

    // when WebView.onMessage called, there is not-http(s) url
    if(url.includes('http')) {
      this.setState({ webViewUrl: url })
    }
  }

  _checkNeededCookies = () => {
    const { cookies, webViewUrl } = this.state;

    if (webViewUrl === 'SUCCESS_URL') {
      if (cookies['cookie-name-for-jwt']) {
        alert(cookies['cookie-name-for-jwt']);
        // do your magic...
      }
    }
  }

  _onMessage = (event) => {
    const { data } = event.nativeEvent;
    const cookies  = data.split(';'); // `csrftoken=...; rur=...; mid=...; somethingelse=...`

    cookies.forEach((cookie) => {
      const c = cookie.trim().split('=');

      const new_cookies = this.state.cookies;
      new_cookies[c[0]] = c[1];

      this.setState({ cookies: new_cookies });
    });

    this._checkNeededCookies();
  }

  render() {
    const jsCode = "window.postMessage(document.cookie)"
    // let jsCode = "window.postMessage(document.cookie= 'login=; expires=Bla bla bla')"; // if you need to write some cookies, not sure if it goes to shared cookies, most probably no :)

    return (
      <WebView
        source={{ uri: 'AUTH_URL' }}
        onNavigationStateChange={this.onNavigationStateChange}
        onMessage={this._onMessage}
        injectedJavaScript={jsCode}
        style={{ flex: 1 }}
      />
    );
  }
}

export default LoginScreen;

https://gist.github.com/kanzitelli/e5d198e96f81b7a8263745043766127c

Hope this work for you.

Answer from Mahendra Pratap on Stack Overflow
🌐
Stack Overflow
stackoverflow.com › questions › 77150756 › webview-cookies-from-react-native-application
security - Webview cookies from react native application - Stack Overflow
in my React native app after logging in the session got stored in the cookies and I can request any secured data from the backend easily but at a specific screen in the app I'm using a webview, now...
🌐
Stack Overflow
stackoverflow.com › questions › tagged › react-native-cookies
Newest 'react-native-cookies' Questions - Stack Overflow
That's why I need to set up the same cookie as for my app and for api call (eg. like to be the same unauthorised user). I've tried to ... ... I am using an external url to handle the authentication for my react-native app. I send the user to a webview with a loginurl.
🌐
npm
npmjs.com › package › @react-native-cookies › cookies
React Native Cookies
With WebKit-Support, cookies are stored in a separate webview store WKHTTPCookieStore and not necessarily shared with other http requests. Caveat is that this store is available upon mounting the component but not necessarily prior so any attempts to set a cookie too early may result in a false positive. To use WebKit-Support, you should be able to simply make advantage of the react-native-webview as is OR alternatively use the webview component like react-native-wkwebview.
      » npm install @react-native-cookies/cookies
    
Published   May 11, 2022
Version   6.2.1
Author   Jason Safaiyeh
🌐
npm
npmjs.com › package › @react-native-community › cookies › v › 2.1.1
react-native-community/cookies
To use this it's required to use a special implementation of the WebView component (e.g. react-native-wkwebview). This special implementation of the WebView component stores the cookies not in NSHTTPCookieStorage anymore.
      » npm install @react-native-community/cookies
    
Published   Oct 08, 2020
Version   2.1.1
Author   Jason Safaiyeh
🌐
FusionAuth
fusionauth.io › community › forum › topic › 2303 › using-react-app-auth-and-react-native-and-getting-access-to-the-profile-pages
Using react app auth and react native and getting access to the profile pages | FusionAuth Forum
January 26, 2023 - I'm looking further into app auth options to share browser instances and/or make sure cookies are shared between the webview which loads the profile page and the App Auth view.
🌐
GitHub
github.com › react-native-webview › react-native-webview › issues › 1814
[Question] Pass cookie with domain in WebView · Issue #1814 · react-native-webview/react-native-webview
January 6, 2021 - const App = () => { return ( <WebView source={{ uri: 'http://example.com', headers: { Cookie: 'cookie1=asdf;domain=.mydomain.com;path=/;cookie2=fdsa;domain=.mydomain.com;path=/;cookie3=aaaa;domain=.mydomain.com;path=/;', }, }} /> ); };
Published   Jan 06, 2021
Top answer
1 of 2
10

You can try the following trick without using any native modules. just go through the Code or URL.

// @flow

import React, { Component } from 'react';
import {
  WebView,
} from 'react-native';

class LoginScreen extends Component {
  state = {
    cookies    : {},
    webViewUrl : ''
  }

  onNavigationStateChange = (webViewState: { url: string }) => {
    const { url } = webViewState;

    // when WebView.onMessage called, there is not-http(s) url
    if(url.includes('http')) {
      this.setState({ webViewUrl: url })
    }
  }

  _checkNeededCookies = () => {
    const { cookies, webViewUrl } = this.state;

    if (webViewUrl === 'SUCCESS_URL') {
      if (cookies['cookie-name-for-jwt']) {
        alert(cookies['cookie-name-for-jwt']);
        // do your magic...
      }
    }
  }

  _onMessage = (event) => {
    const { data } = event.nativeEvent;
    const cookies  = data.split(';'); // `csrftoken=...; rur=...; mid=...; somethingelse=...`

    cookies.forEach((cookie) => {
      const c = cookie.trim().split('=');

      const new_cookies = this.state.cookies;
      new_cookies[c[0]] = c[1];

      this.setState({ cookies: new_cookies });
    });

    this._checkNeededCookies();
  }

  render() {
    const jsCode = "window.postMessage(document.cookie)"
    // let jsCode = "window.postMessage(document.cookie= 'login=; expires=Bla bla bla')"; // if you need to write some cookies, not sure if it goes to shared cookies, most probably no :)

    return (
      <WebView
        source={{ uri: 'AUTH_URL' }}
        onNavigationStateChange={this.onNavigationStateChange}
        onMessage={this._onMessage}
        injectedJavaScript={jsCode}
        style={{ flex: 1 }}
      />
    );
  }
}

export default LoginScreen;

https://gist.github.com/kanzitelli/e5d198e96f81b7a8263745043766127c

Hope this work for you.

2 of 2
0

June 2024 Update:

Tested with the following versions:

 "dependencies": {
    "react": "18.2.0",
    "react-native": "0.73.4",
    "react-native-webview": "^13.7.1"
  }

The injected JS code to trigger the message event has changed to

window.ReactNativeWebView.postMessage(document.cookie)

And here's a working example:

import React from "react";
import { View, StyleSheet } from "react-native";

import WebView from "react-native-webview";

const App = () => {
  const onMessage = (event: any) => {
    const { data } = event.nativeEvent;
    const cookies: string[] = data?.split(";");

    // Here you have access to cookies, e.g. foo=bar
    console.log(cookies);
  };

  // Here I needed to have updated cookie values every 3s
  // so I used an interval to post the data to RN layer
  const JSCode = `
    setInterval(() => {
      window.ReactNativeWebView.postMessage(document.cookie)
    }, 3000); 

    window.addEventListener("beforeunload", function() {
      for (var i = 0; i < setInterval.length; i++) {
        clearInterval(i);
      }
    });
  `;

  return (
    <View style={StyleSheet.absoluteFill}>
      <WebView
        source={{
          uri: "...",
        }}
        injectedJavaScript={JSCode}
        onMessage={onMessage}
        useWebView2
      />
    </View>
  );
};

export default App;
🌐
GitHub
github.com › react-native-webview › react-native-webview › issues › 3856
Are cookies set in react-native-webview automatically reflected in react-native? · Issue #3856 · react-native-webview/react-native-webview
September 30, 2025 - But here’s the strange part: Today at work, after logging in through the WebView, I tried calling another API from the React Native side(not in webview) using axios or fetch without setting any headers manually · When I checked the server logs, the token cookie was automatically included in the request.
Published   Sep 30, 2025
Find elsewhere
Top answer
1 of 1
1

I managed to

Enable Set-Cookie behavior within a WebView

by establishing a socket connection using socket.io-client, so the web socket requests within the WebView will already include cookies in request headers (which will keep connections alive).

Considering react-native-webview uses WKWebView on iOS, there is no way to access cookies in response headers. However, in this particular scenario you can create the socket connection from outside the web view, handle cookies (it seems socket.io-client already does), and then they should be available in the requests within the WebView.

In order to setup socket io in your react-native app, you will need to

  • Install [email protected] (I tried different versions but this was the only one that worked)
  • Assign window.navigator.userAgent = 'react-native'; (since ES6 modules are hoisted, this assignment must not be done in the same file as react-native and socket io imports)
  • Establish your socket connection.

So it should look like:

// userAgent.js
window.navigator.userAgent = 'react-native';

// Wrapper.tsx
import React from 'react';
import {Platform, StyleSheet, View} from 'react-native';
import {WebView} from 'react-native-webview';
// user agent MUST be imported before socket io
import './userAgent';
import io from 'socket.io-client';


export const socket = io('https://your.host.com/', {
  path: '/path/to/socket.io/',
  jsonp: false,
});


type WrapperProps = {
  path: string;
};

function Wrapper({path}: WrapperProps) {
  return (
    <View style={styles.container}>
      <WebView
        allowFileAccess
        allowUniversalAccessFromFileURLs
        allowingReadAccessToURL={path}
        javaScriptEnabled
        originWhitelist={['*']}
        sharedCookiesEnabled
        source={{
          uri:
            Platform.OS === 'ios'
              ? `file://${path}/index.html`
              : `${path}/index.html`,
        }}
        style={styles.webview}
      />
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
  },
  webview: {
    height: '100%',
    width: '100%',
  },
});

export default React.memo(Wrapper);
🌐
Stack Overflow
stackoverflow.com › questions › 53256983 › react-native-get-cookies-from-webview
React-native get cookies from WebView - Stack Overflow
use CookieManager for manage WebViews' cookie issue: developer.android.com/reference/kotlin/android/webkit/… ... You can use react-native-cookies for handling cookies in RN.
🌐
Medium
amlana21.medium.com › how-to-convert-a-react-app-to-a-mobile-app-and-persist-session-cookies-using-react-native-webview-e3b13bfc237f
How to Convert a React App to a Mobile app and Persist session cookies using React-Native Webview or a PWA | by Amlan Chakladar | Medium
August 30, 2020 - Convert the React web app to a mobile app using React-Native and Webview (I will cover an Android app) - Handle Cookies from Webview Convert the React web app to an installable PWA(Progressive Web Application) via TWA(Trusted Web Activity)
🌐
GitHub
github.com › react-native-webview › react-native-webview › issues › 3344
Cookies not being sent to webview for iOS · Issue #3344 · react-native-webview/react-native-webview
March 1, 2024 - Bug description: Web view should be rendering a web page that has a cookie authentication. Instead it is rendering sign in page. This is happening on iOS after I upgraded to react native 0.73+. It ...
Published   Mar 01, 2024
🌐
GitHub
github.com › react-native-webview › react-native-webview › issues › 387
[Feature Request] API to set cookies on webview · Issue #387 · react-native-webview/react-native-webview
March 5, 2019 - Currently, both platforms offer the ability to set custom cookies on their webviews. iOS 2-11: NSHTTPCookieStorage for UIWebView iOS 11+: WKHTTPCookieStore for WKWebView Android: CookieManager Whil...
Published   Mar 05, 2019
🌐
GitHub
github.com › react-native-webview › react-native-webview › issues › 2605
WebView cookies are empty after being sent through custom header · Issue #2605 · react-native-webview/react-native-webview
May 17, 2022 - import React from 'react'; import { Button, SafeAreaView } from 'react-native'; import { WebView } from 'react-native-webview'; const POST_COOKIES = ` window.ReactNativeWebView.postMessage(document.cookie); true; ` function App() { let webview = null; const onMessage = async (event) => { const { data } = event.nativeEvent; console.log('data: ', data) } const postCookies = () => { if(webview){ webview.injectJavaScript(POST_COOKIES); } else { console.log('no webview') } } return ( <SafeAreaView style={{ flex: 1 }}> <WebView ref={(ref) => (webview = ref)} source={{ uri: 'http://example.com/', headers: { Cookie: 'cookie1=asdf;cookie2=dfasdfdas', }, }} originWhitelist={['*']} onMessage={onMessage} sharedCookiesEnabled={true} thirdPartyCookiesEnabled={true} javascriptEnabled={true} /> <Button title="post cookies" onPress={() => postCookies()}/> </SafeAreaView> ); } export default App;
Published   Jul 18, 2022
🌐
GitHub
github.com › react-native-community › react-native-webview › issues › 629
How can get cookie which is set in webview in react-native ...
March 16, 2019 - 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={['*']} />
Published   Jun 06, 2019
🌐
GitHub
github.com › react-native-webview › react-native-webview › issues › 950
How could I get cookie in webview which is set in react-native? · Issue #950 · react-native-webview/react-native-webview
June 7, 2019 - Bug description: I have fetch a request in react-native, then the server response set a cookie named jssession. When I send http request in webview, the request header does't contain the cookie jssessionid. To Reproduce: Expected behavio...
Published   Oct 14, 2019