2

I am facing a strange issue in Firefox (62.0.3). The values set in localStorage are sometimes lost in a new tab.

I can reproduce this with the following HTML, when served by a web server (I used node/express).

<!DOCTYPE html>
<html><body><script>
    window.onload = () => {console.log(window.localStorage.myVal || 'undefined')}
</script></body></html>

Steps:

  1. open page, page displays undefined
  2. run script in console localStorage.myVal='defined'
  3. reload page, page displays defined
  4. when opening the page in a new tab it displays undefined or defined at random. (I opened 10 new tabs and results seemed random)

Maybe I have set something in Firefox which causes this, but since the behaviour is at random I am somewhat puzzled.

The example above is just to demonstrate the problem. The Actual application where this problem first happened was a react/redux application using localStorage.

mplungjan
  • 134,906
  • 25
  • 152
  • 209
Philippe
  • 41
  • 3
  • Try `window.onload = () => {console.log(window.localStorage.myVal || 'undefined')}` and see it it works this way. – dfsq Oct 22 '18 at 11:51
  • https://developer.mozilla.org/en-US/docs/Web/API/Document/write – Teemu Oct 22 '18 at 11:51
  • 1
    NEVER document.write after load - it wipes the page AND the script – mplungjan Oct 22 '18 at 11:51
  • replacing write with log did not change behaviour – Philippe Oct 22 '18 at 11:55
  • Did you ever make progress on this? I am facing the exact same issue with Firefox 66.0.2 on Ubuntu. Annoyingly, appearance of the bug is somewhat random. – tglas Apr 01 '19 at 19:04
  • @tglas: Unfortunately not. It remains to be somewhat annoying, but I have shifted development work to chrome in the meantime. I believe the problem relates to some restrictive privacy setting I have made, but I was unable to determine which one and I didn't find the time to reset all my settings to truly test this. As a side note, I never escalated this to any other board or bug tracker. – Philippe Apr 02 '19 at 16:35
  • 1
    @Philippe: Yesterday I disabled the setting "Delete cookies and site data when Firefox is closed", where I had defined proper exceptions so that it should not have an effect on my test case. However, after disabling the setting, localStorage started to work as it should. This is a pity, since I really hate to disable that privacy option. – tglas Apr 04 '19 at 06:45
  • @tglas: Strange, one would assume this setting only affects Firefox on exit and not opening new tabs. Does not sound like a feature to me:). But thanks a lot, I will try this later. – Philippe Apr 05 '19 at 08:18

0 Answers0