Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save pablocattaneo/a041566d5e9602a54f76ed51ad1755bd to your computer and use it in GitHub Desktop.
Save pablocattaneo/a041566d5e9602a54f76ed51ad1755bd to your computer and use it in GitHub Desktop.

Source: https://chatgpt.com/share/68818171-cb3c-8006-a7ca-402d318a2336

Yes, you can inspect cookies in Safari inside the iOS Simulator, even when using RNCWebView (i.e., react-native-webview), but there are a few things to understand:


✅ Where Cookies Are Stored (iOS Simulator)

When you use RNCWebView, under the hood it's using WKWebView on iOS. Cookies and other data are managed by WKHTTPCookieStore.

Safari’s Web Inspector:

You can inspect WebView content only if RNCWebView is configured with debugging enabled, and you're running it in a debug build.


🔍 How to Inspect Cookies

  1. Enable Web Inspector in Safari:

    • Open Safari.
    • Go to Preferences > Advanced.
    • Enable "Show Develop menu in menu bar".
  2. Run Your App in the iOS Simulator (with RNCWebView displaying the page you want).

  3. Open Safari > Develop > Simulator > [Your WebView Page]:

    • This will open Web Inspector for the WebView.
    • Go to the "Storage" tab > Cookies to inspect them.

Note: This only works if the web page inside the WebView is configured to allow inspection. For example, it must not block it via headers like X-Frame-Options or Content-Security-Policy.


⚠️ Gotchas

  • If you're using incognito or sharedCookiesEnabled: false, cookies may not be saved or accessible via the Web Inspector.
  • On iOS, cookie persistence between app launches may require sharedCookiesEnabled: true and usage of WKHTTPCookieStore.

📦 Extra Tip (If Needed)

If you want to access cookies programmatically (e.g., from React Native), you can use:

import CookieManager from '@react-native-cookies/cookies';

CookieManager.get('https://yourdomain.com').then(cookies => {
  console.log('Cookies:', cookies);
});

Yes, you can inspect cookies in RNCWebView on Android, but it's a bit trickier than on iOS because there is no built-in Web Inspector like Safari’s. Still, you have several options:


✅ Option 1: Use Chrome Remote Debugging (for WebViews)

You can inspect RNCWebView in your Android emulator or real device using Chrome:

Steps:

  1. Enable WebView Debugging in React Native (if you're in debug mode, this is usually already enabled):
import { WebView } from 'react-native-webview';
WebView.setWebContentsDebuggingEnabled(true); // Optional, usually not needed in debug builds
  1. Run Your App in Android Emulator with the WebView active.

  2. Open Chrome on your desktop and go to:

    chrome://inspect
    
  3. Find your Android device or emulator listed, and click "inspect" under your app.

  4. In the DevTools window, you can:

    • View the DOM
    • Inspect network traffic
    • View cookies via the Application > Cookies tab.

⚠️ Requirements & Notes:

  • Your WebView must be loading http(s) pages (not file://).
  • Cookies set via JavaScript or HTTP headers should be visible.
  • You must have USB debugging enabled (for real devices).
  • Works in debug builds only.

✅ Option 2: Access Cookies Programmatically (React Native)

Like on iOS, use the @react-native-cookies/cookies library:

import CookieManager from '@react-native-cookies/cookies';

CookieManager.get('https://yourdomain.com').then(cookies => {
  console.log('Cookies on Android:', cookies);
});

🔁 This works on both Android and iOS and is useful for debugging persistent cookie issues or for syncing cookies manually.


Summary

Platform Tool Can Inspect Cookies? Notes
iOS Safari Web Inspector ✅ Yes Use Develop > Simulator
Android Chrome Remote Debugging (inspect) ✅ Yes Go to chrome://inspect
Both @react-native-cookies/cookies ✅ Yes Use programmatically
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment