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.

Cookies passed in custom header not working

See original GitHub issue

Bug description: I am trying to pass a cookie via a custom header, but it does not seem to work at all. My site looks for a specific cookie on certain pages and it doesn’t seem to find it. I have also tried a super simple test example, exactly like the documentation, except the url is hitting a test page on a local server that creates an alert with all cookies. The documentation I am following is here: https://github.com/react-native-community/react-native-webview/blob/master/docs/Guide.md#working-with-custom-headers-sessions-and-cookies

Am I missing something???

To Reproduce:

  1. Spin up a local web server with a simple web page that uses JS to show an alert with all the document’s cookies. JS example:
<script type="text/javascript">
  alert('document.cookie='+document.cookie);
</script>
  1. Create a simple RN app with the latest react-native-webview module, and add the following code:
const App = () => {
  return (
    <WebView
      source={{
        uri: 'http://localhost:8083', // location of the web page of step 1
        headers: {
          Cookie: 'cookie1=asdf; cookie2=dfasdfdas',
        },
      }}
      sharedCookiesEnabled={true}
    />
  );
};
  1. Notice that none of the cookies set in the custom header are not found.

Expected behavior: Cookies passed in a custom header can be read by the receiving web page.

Environment:

  • OS: macOS Catalina
  • OS version: 10.15.4
  • react-native version: 0.62.2
  • react-native-webview version: 9.4.0

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:8
  • Comments:11

github_iconTop GitHub Comments

7reactions
Matiyeucommented, Jun 2, 2021

Same for me, the cookies are not passed except with incognito=true … Has anyone found a solution?

4reactions
dwxwcommented, Jul 22, 2020

I’ve also found this, but only on Android, iOS works fine. Adding incognito mode made Android work, but sadly I can’t use incognito mode for other reasons. Interestingly it only seems to happen the first time I open the webview, subsequent times it is receiving the cookies for me.

Read more comments on GitHub >

github_iconTop Results From Across the Web

7 Keys to the Mystery of a Missing Cookie - Medium
Troubleshooting tip: open the developer console and check in the Network tab what are the response headers from OPTIONS . Solution tip: On...
Read more >
set-cookie header not working - Stack Overflow
I found here that my Set-Cookie header was not accessible to my client unless I added it to the exposed-header header. Hope this...
Read more >
Logic Apps custom connector with Cookie header
Hi,. I am trying to call an api through a custom connector (Gateway enabled) through a logic app. There are 2 custom connectors....
Read more >
HTTP headers - MDN Web Docs - Mozilla
HTTP headers let the client and the server pass additional information with an HTTP ... General warning information about possible problems.
Read more >
Setting and modifying Headers and Cookies - Twilio
The Response object exposes the following methods to allow you to customize what headers are sent in response to incoming requests. Headers. setHeaders() ......
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