cookie-store icon indicating copy to clipboard operation
cookie-store copied to clipboard

Infinite looping on Cookie Store API with event listener

Open RupinMittal opened this issue 1 year ago • 7 comments

Consider this code:

function runLoopingCase() { cookieStore.onchange = (event) => { printChangeEvent('Cookie got changed\n'); document.cookie="a=b"; }; document.cookie="a=b"; }

The spec says that any time a cookie is set, we should fire an event. This would mean that the above code will loop infinitely.

And indeed, on Chrome and Safari it does. A fix for this would be: "Do not fire the change event if the cookie being set is identical to an already-existing cookie". This makes logical sense and is how Mozilla fixed the issue: https://phabricator.services.mozilla.com/D217573.

Can we modify the spec to enforce that events are not fired when an identical cookie is set?

RupinMittal avatar Jan 28 '25 19:01 RupinMittal