How do I make the data of a web app “persistent” as opposed to “best-effort”? I want to avoid the data being cleared when there is not enough space

故事扮演 提交于 2019-12-25 04:14:27

问题


According to https://developer.mozilla.org/en-US/docs/Web/API/StorageManager/persist you can mark a box as "persistent" as follows:

if (navigator.storage && navigator.storage.persist)
  navigator.storage.persist().then(function(persistent) {
    if (persistent)
      console.log("Storage will not be cleared except by explicit user action");
    else
      console.log("Storage may be cleared by the UA under storage pressure.");
  });

According to https://developer.mozilla.org/en-US/docs/Web/API/Storage_API:

"If a box is marked as "persistent", the contents won't be cleared by the user agent without either the data's origin itself or the user specifically doing so. This includes scenarios such as the user selecting a "Clear Caches" or "Clear Recent History" option. The user will be asked specifically for permission to remove persistent site storage units."

However, clearing recent history in Chrome and Firefox removes the data without asking me for permission. What did I miss?


回答1:


Clearing recent history in Chrome and Firefox counts as an 'explicit user action'. You should get a confirm dialog, even if it does not mention 'storage'. The average user would not even know what 'persistent storage' is.



来源:https://stackoverflow.com/questions/51808081/how-do-i-make-the-data-of-a-web-app-persistent-as-opposed-to-best-effort-i

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!