Giter Site home page Giter Site logo

Comments (7)

eighthjouster avatar eighthjouster commented on July 19, 2024 1

There is an easy workaround: Just before deleting the cookie, set it again to any value (an empty string should be fine). Firefox will of course "revive" the cookie, and clearing it will work at that point. For example:

// Let's delete the 'arepa' cookie:

    cookieService.write('arepa', '');
    cookieService.clear('arepa');

// The 'arepa' cookie is now gone.

from ember-cookies.

marcoow avatar marcoow commented on July 19, 2024 1

Thanks for the details @eighthjouster! I just confirmed the respective test breaks in Firefox.

from ember-cookies.

marcoow avatar marcoow commented on July 19, 2024

Any Error? Is the cookie just not cleared? Does it have a path, domain, expiration etc.?

from ember-cookies.

eighthjouster avatar eighthjouster commented on July 19, 2024

I can confirm that this is a bug, although it's not an ember-cookie bug. It's a Firefox bug (see: https://bugzilla.mozilla.org/show_bug.cgi?id=691973 ), and it's only related to cookies that are already expired.

Chrome isn't affected, so ember-cookies works flawlessly there.

Steps to reproduce:

  1. Create a cookie with an expiration timestamp 10 seconds from now.
  2. Wait until it expires.
  3. Check Firefox's cookies. The cookie will still be there.
  4. Attempt to delete cookie via Javascript. Nope. Not happening.

Here's a simple HTML (must be accessed through a local web server, or enable cookies with local files) that can help reproduce the problem (keep the dev console open in the Local Storage/Cookies section):

<html>
<body>

<input type="button" id="cookiebutton" onclick="cookieButton()" value="Create cookie"></button>
<input type="button" id="cookiedeletebutton" onclick="hardDeleteCookie()" value="HARD delete cookie"></button>
<div id="cookiemessage">No cookie (supposedly)</div>
<script>
  function cookieButton() {
    if (cookiebutton.value === 'Create cookie') {
      cookiebutton.value = 'Delete cookie';
      createCookie();
      setTimeout(announceExpiredCookie, 5000);
    }
    else if (cookiebutton.value === 'Delete cookie') {
      deleteCookie();
    }
  }
  
  function createCookie() {
    document.cookie = 'oneCookie=1;max-age=5;';
    cookiemessage.innerHTML = 'Cookie created.';
  }
  
  function deleteCookie() {
    document.cookie = 'oneCookie=1;expires=Thu, 01 Jan 1970 00:00:01 GMT';
    cookiemessage.innerHTML = 'Cookie deleted (supposedly)';
  }
  
  function hardDeleteCookie() {
    document.cookie = 'oneCookie=1;max-age=5;';
    document.cookie = 'oneCookie=1;expires=Thu, 01 Jan 1970 00:00:01 GMT';
    cookiemessage.innerHTML = 'Cookie hard deleted!';
  }
  
  function announceExpiredCookie() {
    cookiemessage.innerHTML = 'Cookie deleted (supposedly) or expired.';
  }

</script>

</body>
</html>

from ember-cookies.

trdp30 avatar trdp30 commented on July 19, 2024

This issue is happening for expiry time, which is not getting set properly. Facing this issue in chrome also.
I'm doing this for clearing, which cleared on expired.

if(cookies.read([key])) {
  cookies.write([key], '', { path: '/', expires: moment().toDate()});
}

from ember-cookies.

marcoow avatar marcoow commented on July 19, 2024

@trdp30 how is that cookie written in the first place?

from ember-cookies.

wagenet avatar wagenet commented on July 19, 2024

I'm seeing issue with this in Chrome now.

from ember-cookies.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.