Local Storage is not stored value.
firefox 67.0.3 (android) firefox 68.0b14 (android) (opera 52.4.2517.140781 (android))
Local Storage is not stored value. Wrote a simple example. It shows the current value of 'LS'. Went clicked in the monitor. The value of 'LS' has changed . Closed the browser - opened and the value 'LS' is not preserved.
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <meta name="robots" content="index, follow"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="copyright" content=""> <meta name="keywords" content=""> <meta name="description" content="localstprage"> <title>localstoragetest</title> <style> *{margin: 0px; padding: 0px;} #iphone, #android{font-size: 28px;} #del{width: 50px; height: 50px; float: right; background-color: green;} </style> <script> window.addEventListener('click', function(e) // срабатывает при загрузке страницы БЕЗ CSS { "use strict"; var id = e.target.id; var iphone = document.getElementById("iphone"); var cur_LS = localStorage.getItem("test"); if (cur_LS === "123") {localStorage.setItem("test","ABC");} if (cur_LS === "ABC") {localStorage.setItem("test","123");} if (cur_LS === null) {localStorage.setItem("test","ABC");} if (id === "del") {localStorage.removeItem("test");} cur_LS = localStorage.getItem("test"); iphone.textContent = "set_new = "+cur_LS; }); window.addEventListener('DOMContentLoaded', function() // срабатывает при загрузке страницы БЕЗ CSS { "use strict"; var android = document.getElementById("android"); var cur_LS = localStorage.getItem("test"); android.textContent = "read "+cur_LS; }); </script>
Все ответы (6)
revealed new patterns that behave the same in 'opera' and 'firefox' in these versions. If you close the first tab and then the browser data is saved. Or if you refresh the page after changing the data, the data is also saved.
I was able to reproduce the behavior using Firefox Beta 68.1 on Android 6.0.1. As stated, this only shows up if Firefox is swiped off or force stopped. If I had to guess at the issue, I would guess that Firefox is caching changes to localStorage while on mobile to reduce the number of disk writes, and when Firefox is suddenly closed, it loses those cached changes.
I think I have found the issue:
It appears that Firefox caches localStorage writes, and will flush them either after 5 seconds or when other conditions are met. You can see the criteria written in the localStorage code at the gecko-dev repository.
As would be expected, I am unable to reproduce this bug if I wait 5 seconds before closing Firefox.
I believe this could be fixed if Firefox flushes to disk when it detects the app is no longer fully focused. I don't do that much with C++ and Android though, so I wouldn't be the one to tell you.
Изменено
ecc521 said
I think I have found the issue: It appears that Firefox caches localStorage writes, and will flush them either after 5 seconds or when other conditions are met. You can see the criteria written in the localStorage code at the gecko-dev repository. As would be expected, I am unable to reproduce this bug if I wait 5 seconds before closing Firefox. I believe this could be fixed if Firefox flushes to disk when it detects the app is no longer fully focused. I don't do that much with C++ and Android though, so I wouldn't be the one to tell you.
thank you for finding a solution together. and Yes, You're right! If you wait about five seconds. That data is saved.
My suggestions to the developers to make this interval one second. Other browsers do not have this problem.
vipmaster-05 said
ecc521 saidI think I have found the issue: It appears that Firefox caches localStorage writes, and will flush them either after 5 seconds or when other conditions are met. ... I believe this could be fixed if Firefox flushes to disk when it detects the app is no longer fully focused.My suggestions to the developers to make this interval one second.
One of you could file a bug here: https://bugzilla.mozilla.org/
jscher2000 said
vipmaster-05 saidecc521 saidI think I have found the issue: It appears that Firefox caches localStorage writes, and will flush them either after 5 seconds or when other conditions are met. ... I believe this could be fixed if Firefox flushes to disk when it detects the app is no longer fully focused.My suggestions to the developers to make this interval one second.
One of you could file a bug here: https://bugzilla.mozilla.org/
done, hopefully correctly all the issued)
Bug 1565612 The value is not stored in 'Local Storage'. If after changing the value do not wait 3-5 seconds. That is, set a new value and quickly close the browser. New local storage data will be lost.