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

227
Views
Cookie set with javascript disappears after refresh

I'm setting my cookies like this:

document.cookie = `${cookieName}=${JSON.stringify(cookieObject)};path=/;SameSite=Strict;Secure=true;expires=${someDate.toUTCString()};`

Everything is fine at first. But when I refresh, the cookie disappears and firefox console tells me a message:

Cookie “thecookiename” will be soon rejected because it has the “SameSite” attribute set to “None” or an invalid value, without the “secure” attribute.

If I refresh again, the message disappears and the cookie is also gone.

Chrome acts the same, but minus the message.

Edit

I realized, the problem might be related to the fact, that I'm overriding the document.cookie setter.

document.setCookie = document.__lookupSetter__('cookie');
document.newCookieSetter= (cookie) => {
    // here I check, whether a cookie is allowed or not. Calls for an api endpoint to get the information.

    if (cookieDataRecieved() && cookieIsAllowed(cookie)) {
        return document.setCookie(cookie);
    }
    cacheCookie(cookie); // If cookie data has loaded, try checking again.  
}

document.__defineSetter__('cookie', document.newCookieSetter);

The problem applies to every cookie added through the document.cookie = "somecookie";

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

0

The Secure attribute has no value, it's just a bare attribute (present or absent), so just replace Secure=true with Secure.

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!