Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

65
Views
Mobile Google Chrome not sending the cookies

I wrote a simple Express.js server which only sets a cookie named hello-world and returns the request headers. Here is the code:

const app = require('express')()

app.get('/', (req, res) => {
  res.cookie('hello-world', 'this-is-the-value-of-cookie')
  res.json(req.headers)
})

app.listen(80, '0.0.0.0')

The problem is that mobile Google Chrome dose not send the cookies in the first request. Here is a demo of it: https://file.io/OIilmHoA2IKK

In the demo, I use the Android Studio's emulator and nip.io wildcard DNS. I simply start the Express.js server on my local machine and then access it via http://10.0.2.2.nip.io

As you can see in the demo, I first open the page and refresh to make sure hello-world cookie is set. Then I close Google Chrome and reopen it again. But the first time I open the page, there is still no hello-world cookie.

What did I do wrong here? I want the hello-world cookie be sent even in the first request after browser restarts.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

It is not entirely clear from you code snippet, but I assume that you are creating a session cookie instead of a persistent cookie. Therefore the cookie is gone, when you close and reopen the browser.

You can create a persistent cookie by adding an expiration date to your cookie value. Your cookie will be stored until it expires (or is deleted by the user). That date parameter has to be formatted as a UTC string. You could do it like this:

res.cookie('hello-world', 'this-is-the-value-of-cookie', { expires: new Date(2030, 0) });
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!