Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

localStorage cannot be removed in Chrome

I have extremely weird behaviour in Chrome: Version 61.0.3163.79 (Official Build) (64-bit).

I keep a token in localStorage and I cannot remove it permanently. Now matter whether I do it programmatically by localStorage.removeItem('token') or by Chrome tools in the application tab, this token keeps coming back. After removing the token, when I refresh the page, token is not there, but once I close this tab and open a new one for my application, this token is resurrected!

Also, when I have multiple tabs opened, when I refresh pages, some tabs see this token, some not, and it shouldn't be like this as localStorage should be global for all tabs.

I have no idea what this is, a new Chrome bug?

like image 566
klis87 Avatar asked Sep 09 '17 13:09

klis87


2 Answers

I noticed the same behavior and verified that it did not work this way in Chrome version 60.

It looks like a bug in Chrome: https://bugs.chromium.org/p/chromium/issues/detail?id=765524

As a workaround, I changed

localStorage.removeItem('token')

to

localStorage.setItem('token', '')

and that seems to give me the expected behavior (i.e. logout works).

like image 70
Matt Terski Avatar answered Oct 03 '22 02:10

Matt Terski


In 2022 it seems still be the case, at least I've failed to remove an item with the mouse right click → context menu → delete

But I've managed to do it via a double click on the key value, which puts you sort of into an edit mode, so that one can just then press Backspace and the key is removed.

like image 27
Dmitry Koroliov Avatar answered Oct 03 '22 03:10

Dmitry Koroliov